| 1 | #[cfg(feature = "gettext")] |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 3 | ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#}, |
| 4 | syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#, |
| 5 | }; |
| 6 | |
| 7 | #[cfg(feature = "gettext")] |
| 8 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) mod checkrust-analyzer cargo sudo-rs 0.2.14 gettext/check/; |
| 9 | |
| 10 | #[cfg(feature = "gettext")] |
| 11 | // If the locale isn't detected to be UTF-8, or couldn't be switched, the user |
| 12 | // will get the default messages. |
| 13 | static TEXT_DOMAINrust-analyzer cargo sudo-rs 0.2.14 gettext/TEXT_DOMAIN.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<&'static CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#> = OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().(); |
| 14 | |
| 15 | #[cfg(feature = "gettext")] |
| 16 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn textdomainrust-analyzer cargo sudo-rs 0.2.14 gettext/textdomain().(domain: &'static CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) { |
| 17 | use libcrust-analyzer cargo libc 0.2.186 crate/::{CODESETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/CODESET., LC_ALLrust-analyzer cargo libc 0.2.186 unix/linux_like/LC_ALL., nl_langinforust-analyzer cargo libc 0.2.186 nl_langinfo()., setlocalerust-analyzer cargo libc 0.2.186 setlocale().}; |
| 18 | let utf8 = c"UTF-8"; |
| 19 | |
| 20 | // SAFETY: in all cases the functions are passed valid null-terminated C strings; |
| 21 | // in the case of nl_langinfo, it is guaranteed by the spec to always return a valid |
| 22 | // null-terminated C string as well, making the CStr::from_ptr call safe. |
| 23 | unsafe { |
| 24 | if setlocalerust-analyzer cargo libc 0.2.186 setlocale().(LC_ALLrust-analyzer cargo libc 0.2.186 unix/linux_like/LC_ALL., CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString][Default]default().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()).is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 25 | return; |
| 26 | }; |
| 27 | if CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(nl_langinforust-analyzer cargo libc 0.2.186 nl_langinfo().(CODESETrust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/CODESET.)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().utf8 { |
| 28 | return; |
| 29 | } |
| 30 | if gettext_sysrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext_sys/::bind_textdomain_codesetrust-analyzer cargo sudo-rs 0.2.14 bind_textdomain_codeset().(domain.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), utf8.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()).is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 31 | return; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | TEXT_DOMAINrust-analyzer cargo sudo-rs 0.2.14 gettext/TEXT_DOMAIN..setrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]set().(domain).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("only set the locale once") |
| 36 | } |
| 37 | |
| 38 | #[cfg(feature = "gettext")] |
| 39 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) mod displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/ { |
| 40 | // Based on <https://lukaskalbertodt.github.io/2019/12/05/generalized-autoref-based-specialization.html> |
| 41 | pub struct Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(pub T); |
| 42 | |
| 43 | pub trait Convertrust-analyzer cargo sudo-rs 0.2.14 gettext/display/Convert# { |
| 44 | fn displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/Convert#display().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 45 | } |
| 46 | |
| 47 | pub trait Referencerust-analyzer cargo sudo-rs 0.2.14 gettext/display/Reference# { |
| 48 | fn displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/Reference#display().(&self) -> &str; |
| 49 | } |
| 50 | |
| 51 | impl<T: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Convertrust-analyzer cargo sudo-rs 0.2.14 gettext/display/Convert# for Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#<T> { |
| 52 | fn displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`Wrap<T>`][Convert]display().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 53 | self.0rust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#0..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl<T: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> Referencerust-analyzer cargo sudo-rs 0.2.14 gettext/display/Reference# for &Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#<T> { |
| 58 | fn displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().(&self) -> &str { |
| 59 | self.0rust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#0..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().() |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[cfg(feature = "gettext")] |
| 65 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn gettextrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext().(text: &'static CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) -> &'static str { |
| 66 | // SAFETY: |
| 67 | // - dggettext expects its first argument to be NULL or a pointer to a |
| 68 | // valid C string; its second argument should always be a valid C string |
| 69 | // - dgettext() is guaranteed to return a pointer to a statically |
| 70 | // allocated null-terminated string; this string is also constant (i.e. |
| 71 | // it will be unmodified by future calls to gettext.) |
| 72 | unsafe { |
| 73 | CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(gettext_sysrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext_sys/::dgettextrust-analyzer cargo sudo-rs 0.2.14 dgettext().( |
| 74 | TEXT_DOMAINrust-analyzer cargo sudo-rs 0.2.14 gettext/TEXT_DOMAIN. |
| 75 | .getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get().() |
| 76 | .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(), |domain| domain.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), |
| 77 | text.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 78 | )) |
| 79 | } |
| 80 | .to_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_str().() |
| 81 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("translation files are corrupted") |
| 82 | } |
| 83 | |
| 84 | #[cfg(feature = "gettext")] |
| 85 | macro_rules! cstrrust-analyzer cargo sudo-rs 0.2.14 gettext/cstr! { |
| 86 | ($lit:literal) => {{ |
| 87 | // this `const` item produces compile time errors = it performs the checks at compile time |
| 88 | const CS: &'static std::ffi::CStr = |
| 89 | match std::ffi::CStr::from_bytes_until_nul(concat!($lit, "\0").as_bytes()) { |
| 90 | Ok(x) => x, |
| 91 | Err(_) => panic!("string literal did not pass CStr checks"), |
| 92 | }; |
| 93 | CS |
| 94 | }}; |
| 95 | } |
| 96 | |
| 97 | #[cfg(feature = "gettext")] |
| 98 | macro_rules! xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat! { |
| 99 | ($text: literal) => {{ |
| 100 | const _: () = $crate::gettext::check::check_keys($text, &[]); |
| 101 | $crate::gettext::gettext(cstr!($text)) |
| 102 | }}; |
| 103 | |
| 104 | ($text: literal $(, $id: ident = $val: expr)* $(,)?) => {{ |
| 105 | #[allow(unused)] |
| 106 | use $crate::gettext::display::{Convert, Reference, Wrap}; |
| 107 | use std::ops::Deref; |
| 108 | |
| 109 | const _: () = $crate::gettext::check::check_keys( |
| 110 | $text, |
| 111 | &[$(stringify!($id)),*] |
| 112 | ); |
| 113 | |
| 114 | let result = $crate::gettext::gettext(cstr!($text)); |
| 115 | $( |
| 116 | let result = result.replace( |
| 117 | concat!("{", stringify!($id), "}"), |
| 118 | (&&Wrap(&$val)).display().deref(), |
| 119 | ); |
| 120 | )* |
| 121 | |
| 122 | result |
| 123 | }}; |
| 124 | } |
| 125 | |
| 126 | #[cfg(not(feature = "gettext"))] |
| 127 | macro_rules! xlat { |
| 128 | ($text: literal) => { $text }; |
| 129 | |
| 130 | ($text: literal $(, $id: ident = $val: expr)* $(,)?) => {{ |
| 131 | format!($text $(,$id = $val)*) |
| 132 | }}; |
| 133 | } |
| 134 | |
| 135 | #[cfg(feature = "gettext")] |
| 136 | macro_rules! xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write! { |
| 137 | ($f: expr, $fmt: literal $(, $id: ident = $val: expr)* $(,)?) => { |
| 138 | write!($f, "{}", xlat!($fmt $(, $id = $val)*)) |
| 139 | }; |
| 140 | } |
| 141 | |
| 142 | #[cfg(feature = "gettext")] |
| 143 | macro_rules! xlat_printlnrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_println! { |
| 144 | ($fmt: literal $(, $id: ident = $val: expr)* $(,)?) => { |
| 145 | println_ignore_io_error!("{}", xlat!($fmt $(, $id = $val)*)) |
| 146 | }; |
| 147 | } |
| 148 | |
| 149 | #[cfg(not(feature = "gettext"))] |
| 150 | macro_rules! xlat_write { |
| 151 | ($f: expr, $fmt: literal $(, $id: ident = $val: expr)* $(,)?) => { |
| 152 | write!($f, $fmt $(, $id = $val)*) |
| 153 | }; |
| 154 | } |
| 155 | |
| 156 | #[cfg(not(feature = "gettext"))] |
| 157 | macro_rules! xlat_println { |
| 158 | ($fmt: literal $(, $id: ident = $val: expr)* $(,)?) => { |
| 159 | println_ignore_io_error!($fmt $(, $id = $val)*) |
| 160 | }; |
| 161 | } |
| 162 | |
| 163 | //These are all defined in POSIX. |
| 164 | #[cfg(feature = "gettext")] |
| 165 | mod gettext_sysrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext_sys/ { |
| 166 | #[cfg_attr(target_os = "freebsd", link(name = "intl"))] |
| 167 | unsafe extern "C" { |
| 168 | pub fn dgettextrust-analyzer cargo sudo-rs 0.2.14 dgettext().( |
| 169 | domain: *const libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, |
| 170 | msgid: *const libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, |
| 171 | ) -> *mut libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#; |
| 172 | |
| 173 | pub fn bind_textdomain_codesetrust-analyzer cargo sudo-rs 0.2.14 bind_textdomain_codeset().( |
| 174 | domain: *const libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, |
| 175 | codeset: *const libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, |
| 176 | ) -> *mut libcrust-analyzer cargo libc 0.2.186 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | #[cfg(test)] |
| 181 | mod testrust-analyzer cargo sudo-rs 0.2.14 gettext/test/ { |
| 182 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 183 | #[cfg(feature = "gettext")] |
| 184 | fn it_worksrust-analyzer cargo sudo-rs 0.2.14 gettext/test/it_works().() { |
| 185 | use superrust-analyzer cargo sudo-rs 0.2.14 gettext/::*; |
| 186 | textdomainrust-analyzer cargo sudo-rs 0.2.14 gettext/textdomain().(c"libc"); |
| 187 | let input = c"Hello World"; |
| 188 | // inputs that are not translated are not translated |
| 189 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(gettextrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext().(input), input.to_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 190 | // .. in fact they are the same object |
| 191 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(gettextrust-analyzer cargo sudo-rs 0.2.14 gettext/gettext().(input).as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), input.to_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().()); |
| 192 | |
| 193 | if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("LANG").unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("nl") { |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat!!("Operation not permitted"), "Actie is niet toegestaan"); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 199 | fn var_substrust-analyzer cargo sudo-rs 0.2.14 gettext/test/var_subst().() { |
| 200 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 201 | xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat!!("{hello} {world}", world = "world", hello = "hello"), |
| 202 | "hello world" |
| 203 | ); |
| 204 | |
| 205 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat!!("five = {five}", five = 5), "five = 5"); |
| 206 | } |
| 207 | |
| 208 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 209 | #[cfg(feature = "gettext")] |
| 210 | fn str_optimizedrust-analyzer cargo sudo-rs 0.2.14 gettext/test/str_optimized().() { |
| 211 | use superrust-analyzer cargo sudo-rs 0.2.14 gettext/::displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/::{Referencerust-analyzer cargo sudo-rs 0.2.14 gettext/display/Reference#, Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#}; |
| 212 | |
| 213 | // in principle the assert_eq's below could be replaced by "expect(unused)" on this trait |
| 214 | #[allow(unused_imports)] |
| 215 | use superrust-analyzer cargo sudo-rs 0.2.14 gettext/::displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/::Convertrust-analyzer cargo sudo-rs 0.2.14 gettext/display/Convert#; |
| 216 | |
| 217 | let foo: &str = "foo"; |
| 218 | let addr = foo.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(); |
| 219 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(&foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 220 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 221 | |
| 222 | let foo: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = "foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 223 | let addr = foo.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(); |
| 224 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(&foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 225 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 226 | |
| 227 | let foo: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str> = "foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().into_boxed_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_boxed_str().(); |
| 228 | let addr = foo.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(); |
| 229 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(&foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 230 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 231 | |
| 232 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#; |
| 233 | let foo: SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString# = SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#::newrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]new().("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 234 | let addr = foo.as_strrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]as_str().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(); |
| 235 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(&foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 236 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&&Wraprust-analyzer cargo sudo-rs 0.2.14 gettext/display/Wrap#(foo)).displayrust-analyzer cargo sudo-rs 0.2.14 gettext/display/impl#[`&Wrap<T>`][Reference]display().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_ptr().(), addr); |
| 237 | } |
| 238 | } |