Debian Codegraph @

src/ext/ustr.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#;
2 use 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/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#;
6
7 // U meaning micro
8 // a micro-string is either a reference-counted string or a static string
9 // this guarantees these are cheap to clone everywhere
10 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
11 pub enum UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
12 Staticrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Static#(&'static str),
13 Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<str>),
14 }
15
16 impl UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
17 pub fn newrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr]new().(s: &str) -> Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr] {
18 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<str>`][`From<String>`]from().(s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))
19 }
20
21 /// Apply [str::strip_prefix], without copying if possible.
22 pub fn strip_prefixrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr]strip_prefix().(this: &Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr], prefix: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr]> {
23 match this {
24 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Staticrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Static#(s) => s.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(prefix).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr]::Staticrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Static#),
25 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(s) => s.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(prefix).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr]::Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())),
26 }
27 }
28 }
29
30 impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
31 type Targetrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Deref]Target# = str;
32
33 #[inline]
34 fn derefrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Deref]deref().(&self) -> &str {
35 match self {
36 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Staticrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Static#(s) => s,
37 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(s) => s,
38 }
39 }
40 }
41
42 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
43 #[inline]
44 fn hashrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
45 // Forward the hash to the string representation of this
46 // A derive(Hash) encodes the enum discriminant
47 (*rust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[str][Hash]hash().(state);
48 }
49 }
50
51 impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<str> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
52 #[inline]
53 fn borrowrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`Borrow<str>`]borrow().(&self) -> &str {
54 self
55 }
56 }
57
58 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
59 fn eqrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`PartialEq<Self>`]eq().(&self, other: &UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#) -> bool {
60 (*rust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][`PartialEq<Self>`]eq().(&*rust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other)
61 }
62 }
63
64 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'static str> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
65 #[inline]
66 fn fromrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<&'static str>`]from().(s: &'static str) -> Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<&'static str>`] {
67 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Staticrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Static#(s)
68 }
69 }
70
71 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
72 fn fromrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<&'a UStr>`]from().(value: &'a UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#) -> Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<&'a UStr>`] {
73 value.clonerust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Clone]clone().()
74 }
75 }
76
77 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
78 #[inline]
79 fn fromrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<String>`]from().(s: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`From<String>`] {
80 UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#::Sharedrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr#Shared#(s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
81 }
82 }
83
84 impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
85 #[inline]
86 fn fmtrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
87 f.padrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]pad().(self)
88 }
89 }
90
91 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
92 #[inline]
93 fn fmtrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
94 f.padrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]pad().(self)
95 }
96 }
97
98 // manual impls because otherwise things get a little screwy with lifetimes
99
100 #[cfg(feature = "offline")]
101 impl<'de> serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
102 fn deserializerust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][`Deserialize<'de>`], <D as serderust-analyzer cargo serde 1.0.229 crate/::Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#>
103 where
104 D: serderust-analyzer cargo serde 1.0.229 crate/::Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>,
105 {
106 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::deserializerust-analyzer cargo serde_core 1.0.229 de/impls/impl#[String][`Deserialize<'de>`]deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
107 }
108 }
109
110 #[cfg(feature = "offline")]
111 impl serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for UStrrust-analyzer cargo sqlx-core 0.8.3 ext/ustr/UStr# {
112 fn serializerust-analyzer cargo sqlx-core 0.8.3 ext/ustr/impl#[UStr][Serialize]serialize().<S>(
113 &self,
114 serializer: S,
115 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<<S as serderust-analyzer cargo serde 1.0.229 crate/::Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, <S as serderust-analyzer cargo serde 1.0.229 crate/::Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#>
116 where
117 S: serderust-analyzer cargo serde 1.0.229 crate/::Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#,
118 {
119 serializer.serialize_strrust-analyzer cargo serde_core 1.0.229 ser/Serializer#serialize_str().(self)
120 }
121 }