1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 error::{BitsTaskError, ErrorStage, ErrorType},
10 use nsstring::nsCString;
11 use std::ffi::OsString;
12 use std::{str, str::FromStr};
14 /// This function is fallible, and the consumers would prefer a BitsTaskError
15 /// in the failure case. To facilitate that, this function takes some params
16 /// that give it the data necessary to construct the BitsTaskError if it fails.
17 /// If it succeeds, those values will be unused.
18 #[allow(non_snake_case)]
19 pub fn nsCString_to_String(
22 error_stage: ErrorStage,
23 ) -> Result<String, BitsTaskError> {
24 match String::from_utf8(value[..].to_vec()) {
26 Err(_) => Err(BitsTaskError::new(
27 ErrorType::NoUtf8Conversion,
34 /// This function is fallible, and the consumers would prefer a BitsTaskError
35 /// in the failure case. To facilitate that, this function takes some params
36 /// that give it the data necessary to construct the BitsTaskError if it fails.
37 /// If it succeeds, those values will be unused.
38 #[allow(non_snake_case)]
39 pub fn nsCString_to_OsString(
42 error_stage: ErrorStage,
43 ) -> Result<OsString, BitsTaskError> {
44 Ok(OsString::from(nsCString_to_String(
51 /// This function is fallible, and the consumers would prefer a BitsTaskError
52 /// in the failure case. To facilitate that, this function takes some params
53 /// that give it the data necessary to construct the BitsTaskError if it fails.
54 /// If it succeeds, those values will be unused.
55 #[allow(non_snake_case)]
56 pub fn Guid_from_nsCString(
59 error_stage: ErrorStage,
60 ) -> Result<Guid, BitsTaskError> {
61 let vector = &value[..].to_vec();
62 let string = match str::from_utf8(vector) {
65 return Err(BitsTaskError::new(
66 ErrorType::NoUtf8Conversion,
72 Guid::from_str(string).map_err(|comedy_error| {
73 BitsTaskError::from_comedy(
74 ErrorType::InvalidGuid,