Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! This crate provides types for identifiers of object files, such as executables, dynamic
2 //! libraries or debug companion files. The concept originates in Google Breakpad and defines two
3 //! types:
4 //!
5 //! - [`CodeId`]: Identifies the file containing source code, i.e. the actual library or
6 //! executable. The identifier is platform dependent and implementation defined. Thus, there is
7 //! no canonical representation.
8 //! - [`DebugId`]: Identifies a debug information file, which may or may not use information from
9 //! the Code ID. The contents are also implementation defined, but as opposed to `CodeId`, the
10 //! structure is streamlined across platforms. It is also guaranteed to be 32 bytes in size.
11 //!
12 //! [`CodeId`]: struct.CodeId.html
13 //! [`DebugId`]: struct.DebugId.html
14
15 #![warn(missing_docs)]
16
17 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/;
18 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/;
19 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/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
20 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/;
21
22 use uuidrust-analyzer cargo uuid 1.25.0 crate/::{Bytesrust-analyzer cargo uuid 1.25.0 Bytes#, Uuidrust-analyzer cargo uuid 1.25.0 Uuid#};
23
24 /// Indicates an error parsing a [`DebugId`](struct.DebugId.html).
25 #[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
26 pub struct ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#;
27
28 impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError# {}
29
30 impl 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# for ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError# {
31 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[ParseDebugIdError][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
32 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid debug identifier")
33 }
34 }
35
36 #[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
37 struct ParseOptionsrust-analyzer cargo debugid 0.8.0 ParseOptions# {
38 allow_hyphensrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_hyphens.: bool,
39 require_appendixrust-analyzer cargo debugid 0.8.0 ParseOptions#require_appendix.: bool,
40 allow_tailrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_tail.: bool,
41 }
42
43 /// Unique identifier for debug information files and their debug information.
44 ///
45 /// This type is analogous to [`CodeId`], except that it identifies a debug file instead of the
46 /// actual library or executable. One some platforms, a `DebugId` is an alias for a `CodeId` but the
47 /// exact rules around this are complex. On Windows, the identifiers are completely different and
48 /// refer to separate files.
49 ///
50 /// The string representation must be between 33 and 40 characters long and consist of:
51 ///
52 /// 1. 36 character hyphenated hex representation of the UUID field
53 /// 2. 1-16 character lowercase hex representation of the u32 appendix
54 ///
55 /// The debug identifier is compatible to Google Breakpad. Use [`DebugId::breakpad`] to get a
56 /// breakpad string representation of this debug identifier.
57 ///
58 /// There is one exception to this: for the old PDB 2.0 format the debug identifier consists
59 /// of only a 32-bit integer + age resulting in a string representation of between 9 and 16
60 /// hex characters.
61 ///
62 /// # Example
63 ///
64 /// ```
65 /// # extern crate debugid;
66 /// use std::str::FromStr;
67 /// use debugid::DebugId;
68 ///
69 /// # fn foo() -> Result<(), ::debugid::ParseDebugIdError> {
70 /// let id = DebugId::from_str("dfb8e43a-f242-3d73-a453-aeb6a777ef75-a")?;
71 /// assert_eq!("dfb8e43a-f242-3d73-a453-aeb6a777ef75-a".to_string(), id.to_string());
72 /// # Ok(())
73 /// # }
74 ///
75 /// # fn main() { foo().unwrap() }
76 /// ```
77 ///
78 /// # In-memory representation
79 ///
80 /// The in-memory representation takes up 32 bytes and can be directly written to storage
81 /// and mapped back into an object reference.
82 ///
83 /// ```
84 /// use std::str::FromStr;
85 /// use debugid::DebugId;
86 ///
87 /// let debug_id = DebugId::from_str("dfb8e43a-f242-3d73-a453-aeb6a777ef75-a").unwrap();
88 ///
89 /// let slice = &[debug_id];
90 /// let ptr = slice.as_ptr() as *const u8;
91 /// let len = std::mem::size_of_val(slice);
92 /// let buf: &[u8] = unsafe { std::slice::from_raw_parts(ptr, len) };
93 ///
94 /// let mut new_buf: Vec<u8> = Vec::new();
95 /// std::io::copy(&mut std::io::Cursor::new(buf), &mut new_buf).unwrap();
96 ///
97 /// let ptr = new_buf.as_ptr() as *const DebugId;
98 /// let new_debug_id = unsafe { &*ptr };
99 ///
100 /// assert_eq!(*new_debug_id, debug_id);
101 /// ```
102 ///
103 /// As long the bytes were written using the same major version of this crate you will be
104 /// able to read it again like this.
105 ///
106 /// [`CodeId`]: struct.CodeId.html
107 /// [`DebugId::breakpad`]: struct.DebugId.html#method.breakpad
108 // This needs to be backwards compatible also in its exact in-memory byte-layout since this
109 // struct is directly mapped from disk in e.g. Symbolic SymCache formats. The first version
110 // of this struct was defined as:
111 //
112 // ```rust
113 // struct DebugId {
114 // uuid: Uuid,
115 // appendix: u32,
116 // _padding: [u8; 12],
117 // }
118 // ```
119 //
120 // For this reason the current `typ` byte represents the type of `DebugId` stored in the
121 // `Bytes`:
122 //
123 // - `0u8`: The `bytes` field contains a UUID.
124 // - `1u8`: The first 4 bytes of the `bytes` field contain a big-endian u32, the remaining
125 // bytes are 0.
126 #[repr(C, packed)]
127 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
128 pub struct DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
129 bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.: Bytesrust-analyzer cargo uuid 1.25.0 Bytes#,
130 appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix.: u32,
131 _paddingrust-analyzer cargo debugid 0.8.0 DebugId#_padding.: [u8; 11],
132 typrust-analyzer cargo debugid 0.8.0 DebugId#typ.: u8,
133 }
134
135 impl DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
136 /// Constructs an empty debug identifier, containing only zeros.
137 pub fn nilrust-analyzer cargo debugid 0.8.0 impl#[DebugId]nil().() -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId] {
138 Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::defaultrust-analyzer cargo debugid 0.8.0 impl#[DebugId][Default]default().()
139 }
140
141 /// Constructs a `DebugId` from its `uuid`.
142 pub fn from_uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_uuid().(uuid: Uuidrust-analyzer cargo uuid 1.25.0 Uuid#) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId] {
143 Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid, 0)
144 }
145
146 /// Constructs a `DebugId` from its `uuid` and `appendix` parts.
147 pub fn from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid: Uuidrust-analyzer cargo uuid 1.25.0 Uuid#, appendix: u32) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId] {
148 DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
149 bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.: *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().uuid.as_bytesrust-analyzer cargo uuid 1.25.0 impl#[Uuid]as_bytes().(),
150 appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix.,
151 typrust-analyzer cargo debugid 0.8.0 DebugId#typ.: 0,
152 _paddingrust-analyzer cargo debugid 0.8.0 DebugId#_padding.: [0; 11],
153 }
154 }
155
156 /// Constructs a `DebugId` from a Microsoft little-endian GUID and age.
157 pub fn from_guid_agerust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_guid_age().(guid: &[u8], age: u32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId], ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#> {
158 if guid.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().16 {
159 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#);
160 }
161
162 let uuid = Uuidrust-analyzer cargo uuid 1.25.0 Uuid#::from_bytesrust-analyzer cargo uuid 1.25.0 builder/impl#[Uuid]from_bytes().([
163 guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().7]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().6]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
164 guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().9]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().11]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().12]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().13]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().14]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., guid[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().15]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
165 ]);
166
167 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#::from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid, age))
168 }
169
170 /// Constructs a `DebugId` from a PDB 2.0 timestamp and age.
171 pub fn from_pdb20rust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_pdb20().(timestamp: u32, age: u32) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId] {
172 // The big-endian byte-order here has to match the one used to read this number in
173 // the DebugId::timestamp method.
174 DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
175 bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.: [
176 (timestamp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().24) as u8,
177 (timestamp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().16) as u8,
178 (timestamp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().8) as u8,
179 timestamp as u8,
180 0u8,
181 0u8,
182 0u8,
183 0u8,
184 0u8,
185 0u8,
186 0u8,
187 0u8,
188 0u8,
189 0u8,
190 0u8,
191 0u8,
192 ],
193 appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix.: age,
194 _paddingrust-analyzer cargo debugid 0.8.0 DebugId#_padding.: [0u8; 11],
195 typrust-analyzer cargo debugid 0.8.0 DebugId#typ.: 1u8,
196 }
197 }
198
199 /// Parses a breakpad identifier from a string.
200 pub fn from_breakpadrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_breakpad().(string: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId], ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#> {
201 let options = ParseOptionsrust-analyzer cargo debugid 0.8.0 ParseOptions# {
202 allow_hyphensrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_hyphens.: false,
203 require_appendixrust-analyzer cargo debugid 0.8.0 ParseOptions#require_appendix.: true,
204 allow_tailrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_tail.: false,
205 };
206 Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::parse_strrust-analyzer cargo debugid 0.8.0 impl#[DebugId]parse_str().(string, options).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#)
207 }
208
209 /// Returns the UUID part of the code module's debug_identifier.
210 ///
211 /// If this is a debug identifier for the PDB 2.0 format an invalid UUID is returned
212 /// where only the first 4 bytes are filled in and the remainder of the bytes are 0.
213 /// This means the UUID has variant [`uuid::Variant::NCS`] and an unknown version,
214 /// [`Uuid::get_version`] will return `None`, which is not a valid UUID.
215 ///
216 /// This may seem odd however does seem reasonable:
217 ///
218 /// - Every [`DebugId`] can be represented as [`Uuid`] and will still mostly look
219 /// reasonable e.g. in comparisons etc.
220 /// - The PDB 2.0 format is very old and very unlikely to appear practically.
221 pub fn uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]uuid().(&self) -> Uuidrust-analyzer cargo uuid 1.25.0 Uuid# {
222 Uuidrust-analyzer cargo uuid 1.25.0 Uuid#::from_bytesrust-analyzer cargo uuid 1.25.0 builder/impl#[Uuid]from_bytes().(self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.)
223 }
224
225 /// Returns the appendix part of the code module's debug identifier.
226 ///
227 /// On Windows, this is an incrementing counter to identify the build.
228 /// On all other platforms, this value will always be zero.
229 pub fn appendixrust-analyzer cargo debugid 0.8.0 impl#[DebugId]appendix().(&self) -> u32 {
230 self.appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix.
231 }
232
233 /// Returns whether this identifier is nil, i.e. it consists only of zeros.
234 pub fn is_nilrust-analyzer cargo debugid 0.8.0 impl#[DebugId]is_nil().(&self) -> bool {
235 self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<[U; N]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<[U; N]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<[U; N]>`]eq().[0u8; 16] && self.appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0
236 }
237
238 /// Returns whether this identifier is from the PDB 2.0 format.
239 pub fn is_pdb20rust-analyzer cargo debugid 0.8.0 impl#[DebugId]is_pdb20().(&self) -> bool {
240 self.typrust-analyzer cargo debugid 0.8.0 DebugId#typ. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1
241 }
242
243 /// Returns a wrapper which when formatted via `fmt::Display` will format a
244 /// a breakpad identifier.
245 pub fn breakpadrust-analyzer cargo debugid 0.8.0 impl#[DebugId]breakpad().(&self) -> BreakpadFormatrust-analyzer cargo debugid 0.8.0 BreakpadFormat#<'_> {
246 BreakpadFormatrust-analyzer cargo debugid 0.8.0 BreakpadFormat# { innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner.: self }
247 }
248
249 fn parse_strrust-analyzer cargo debugid 0.8.0 impl#[DebugId]parse_str().(string: &str, options: ParseOptionsrust-analyzer cargo debugid 0.8.0 ParseOptions#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]> {
250 let is_hyphenated = string.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#9) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("-");
251 if is_hyphenated && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().options.allow_hyphensrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_hyphens. || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().string.is_asciirust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_ascii().() {
252 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
253 }
254
255 // Can the PDB 2.0 format match? This can never be true for a valid UUID.
256 let min_len = if is_hyphenated { 10 } else { 9 };
257 let max_len = if is_hyphenated { 17 } else { 16 };
258 if min_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().string.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() && string.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().max_len {
259 let timestamp_str = string.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#8)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
260 let timestamp = u32::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_str_radix().(timestamp_str, 16).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
261 let appendix_str = match is_hyphenated {
262 true => string.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(9..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
263 false => string.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().,
264 };
265 let appendix = u32::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_str_radix().(appendix_str, 16).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
266 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::from_pdb20rust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_pdb20().(timestamp, appendix));
267 }
268
269 let uuid_len = if is_hyphenated { 36 } else { 32 };
270 let uuid = string.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#uuid_len)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
271 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().options.require_appendixrust-analyzer cargo debugid 0.8.0 ParseOptions#require_appendix. && string.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().uuid_len {
272 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid, 0));
273 }
274
275 let mut appendix_str = &string[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().uuid_len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
276 if is_hyphenated rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitXor<Self>`]bitxor().appendix_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('-') {
277 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; // Require a hyphen if and only if we're hyphenated.
278 } else if is_hyphenated {
279 appendix_str = &appendix_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; // Skip the hyphen for parsing.
280 }
281
282 if options.allow_tailrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_tail. && appendix_str.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().8 {
283 appendix_str = &appendix_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
284 }
285
286 // Parse the appendix, which fails on empty strings.
287 let appendix = u32::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_str_radix().(appendix_str, 16).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
288 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId]::from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid, appendix))
289 }
290
291 /// Returns the PDB 2.0 timestamp.
292 ///
293 /// Only valid if you know this is a PDB 2.0 debug identifier.
294 fn timestamprust-analyzer cargo debugid 0.8.0 impl#[DebugId]timestamp().(&self) -> u32 {
295 u32::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_be_bytes().([self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., self.bytesrust-analyzer cargo debugid 0.8.0 DebugId#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().])
296 }
297 }
298
299 impl fmtrust-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# for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
300 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[DebugId][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
301 let uuid = self.uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]uuid().();
302 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("DebugId")
303 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("uuid", &uuid.hyphenatedrust-analyzer cargo uuid 1.25.0 fmt/impl#[Uuid]hyphenated().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
304 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("appendix", &self.appendixrust-analyzer cargo debugid 0.8.0 impl#[DebugId]appendix().())
305 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
306 }
307 }
308
309 impl 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# for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
310 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[DebugId][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
311 match self.is_pdb20rust-analyzer cargo debugid 0.8.0 impl#[DebugId]is_pdb20().() {
312 true => {
313 let timestamp = self.timestamprust-analyzer cargo debugid 0.8.0 impl#[DebugId]timestamp().();
314 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:08X}", timestamp)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
315 }
316 false => {
317 let uuid = self.uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]uuid().();
318 uuid.fmtrust-analyzer cargo uuid 1.25.0 fmt/impl#[Uuid][Display]fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
319 }
320 }
321 if self.appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
322 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "-{:x}", { self.appendixrust-analyzer cargo debugid 0.8.0 DebugId#appendix. })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
323 }
324 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
325 }
326 }
327
328 impl strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
329 type Errrust-analyzer cargo debugid 0.8.0 impl#[DebugId][FromStr]Err# = ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#;
330
331 fn from_strrust-analyzer cargo debugid 0.8.0 impl#[DebugId][FromStr]from_str().(string: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId][FromStr], ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#> {
332 let options = ParseOptionsrust-analyzer cargo debugid 0.8.0 ParseOptions# {
333 allow_hyphensrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_hyphens.: true,
334 require_appendixrust-analyzer cargo debugid 0.8.0 ParseOptions#require_appendix.: false,
335 allow_tailrust-analyzer cargo debugid 0.8.0 ParseOptions#allow_tail.: true,
336 };
337 Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId][FromStr]::parse_strrust-analyzer cargo debugid 0.8.0 impl#[DebugId]parse_str().(string, options).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(ParseDebugIdErrorrust-analyzer cargo debugid 0.8.0 ParseDebugIdError#)
338 }
339 }
340
341 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Uuidrust-analyzer cargo uuid 1.25.0 Uuid#> for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
342 fn fromrust-analyzer cargo debugid 0.8.0 impl#[DebugId][`From<Uuid>`]from().(uuid: Uuidrust-analyzer cargo uuid 1.25.0 Uuid#) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId][`From<Uuid>`] {
343 DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#::from_uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_uuid().(uuid)
344 }
345 }
346
347 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<(Uuidrust-analyzer cargo uuid 1.25.0 Uuid#, u32)> for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
348 fn fromrust-analyzer cargo debugid 0.8.0 impl#[DebugId][`From<(Uuid, u32)>`]from().(tuple: (Uuidrust-analyzer cargo uuid 1.25.0 Uuid#, u32)) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[DebugId][`From<(Uuid, u32)>`] {
349 let (uuid, appendix) = tuple;
350 DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#::from_partsrust-analyzer cargo debugid 0.8.0 impl#[DebugId]from_parts().(uuid, appendix)
351 }
352 }
353
354 /// Wrapper around [`DebugId`] for Breakpad formatting.
355 ///
356 /// **Example:**
357 ///
358 /// ```
359 /// # extern crate debugid;
360 /// use std::str::FromStr;
361 /// use debugid::DebugId;
362 ///
363 /// # fn foo() -> Result<(), debugid::ParseDebugIdError> {
364 /// let id = DebugId::from_breakpad("DFB8E43AF2423D73A453AEB6A777EF75a")?;
365 /// assert_eq!("DFB8E43AF2423D73A453AEB6A777EF75a".to_string(), id.breakpad().to_string());
366 /// # Ok(())
367 /// # }
368 ///
369 /// # fn main() { foo().unwrap() }
370 /// ```
371 ///
372 /// [`DebugId`]: struct.DebugId.html
373 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
374 pub struct BreakpadFormatrust-analyzer cargo debugid 0.8.0 BreakpadFormat#<'a> {
375 innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner.: &'a DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#,
376 }
377
378 impl<'a> 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# for BreakpadFormatrust-analyzer cargo debugid 0.8.0 BreakpadFormat#<'a> {
379 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[`BreakpadFormat<'a>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
380 match self.innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner..is_pdb20rust-analyzer cargo debugid 0.8.0 impl#[DebugId]is_pdb20().() {
381 true => {
382 let timestamp = self.innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner..timestamprust-analyzer cargo debugid 0.8.0 impl#[DebugId]timestamp().();
383 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:08X}{:x}", timestamp, self.innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner..appendixrust-analyzer cargo debugid 0.8.0 impl#[DebugId]appendix().())
384 }
385 false => {
386 let uuid = self.innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner..uuidrust-analyzer cargo debugid 0.8.0 impl#[DebugId]uuid().();
387 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:X}{:x}", uuid.simplerust-analyzer cargo uuid 1.25.0 fmt/impl#[Uuid]simple().(), self.innerrust-analyzer cargo debugid 0.8.0 BreakpadFormat#inner..appendixrust-analyzer cargo debugid 0.8.0 impl#[DebugId]appendix().())
388 }
389 }
390 }
391 }
392
393 /// Indicates an error parsing a [`CodeId`](struct.CodeId.html).
394 #[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
395 pub struct ParseCodeIdErrorrust-analyzer cargo debugid 0.8.0 ParseCodeIdError#;
396
397 impl errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ParseCodeIdErrorrust-analyzer cargo debugid 0.8.0 ParseCodeIdError# {}
398
399 impl 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# for ParseCodeIdErrorrust-analyzer cargo debugid 0.8.0 ParseCodeIdError# {
400 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[ParseCodeIdError][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
401 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "invalid code identifier")
402 }
403 }
404
405 /// Unique platform-dependent identifier of code files.
406 ///
407 /// This identifier assumes a string representation that depends on the platform and compiler used.
408 /// The representation only retains hex characters and canonically stores lower case.
409 ///
410 /// There are the following known formats:
411 ///
412 /// - **MachO UUID**: The unique identifier of a Mach binary, specified in the `LC_UUID` load
413 /// command header.
414 /// - **GNU Build ID**: Contents of the `.gnu.build-id` note or section contents formatted as
415 /// lowercase hex string.
416 /// - **PE Timestamp**: Timestamp and size of image values from a Windows PE header. The size of
417 /// image value is truncated, so the length of the `CodeId` might not be a multiple of 2.
418 #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:)]
419 pub struct CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
420 innerrust-analyzer cargo debugid 0.8.0 CodeId#inner.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
421 }
422
423 impl CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
424 /// Constructs an empty code identifier.
425 pub fn nilrust-analyzer cargo debugid 0.8.0 impl#[CodeId]nil().() -> Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId] {
426 Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId]::defaultrust-analyzer cargo debugid 0.8.0 impl#[CodeId][Default]default().()
427 }
428
429 /// Constructs a `CodeId` from its string representation.
430 pub fn newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(mut string: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId] {
431 string.retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]retain().(|c| c.is_ascii_hexdigitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_hexdigit().());
432 string.make_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]make_ascii_lowercase().();
433 CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# { innerrust-analyzer cargo debugid 0.8.0 CodeId#inner.: string }
434 }
435
436 /// Constructs a `CodeId` from a binary slice.
437 pub fn from_binaryrust-analyzer cargo debugid 0.8.0 impl#[CodeId]from_binary().(slice: &[u8]) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId] {
438 let mut string = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2);
439
440 for byte in slice {
441 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut string, "{:02x}", byte).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("");
442 }
443
444 Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId]::newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(string)
445 }
446
447 /// Returns whether this identifier is nil, i.e. it is empty.
448 pub fn is_nilrust-analyzer cargo debugid 0.8.0 impl#[CodeId]is_nil().(&self) -> bool {
449 self.innerrust-analyzer cargo debugid 0.8.0 CodeId#inner..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().()
450 }
451
452 /// Returns the string representation of this code identifier.
453 pub fn as_strrust-analyzer cargo debugid 0.8.0 impl#[CodeId]as_str().(&self) -> &str {
454 self.innerrust-analyzer cargo debugid 0.8.0 CodeId#inner..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()
455 }
456 }
457
458 impl 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# for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
459 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[CodeId][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
460 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.innerrust-analyzer cargo debugid 0.8.0 CodeId#inner.)
461 }
462 }
463
464 impl fmtrust-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# for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
465 fn fmtrust-analyzer cargo debugid 0.8.0 impl#[CodeId][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
466 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "CodeId({})", self)
467 }
468 }
469
470 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 CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
471 fn fromrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<String>`]from().(string: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<String>`] {
472 Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<String>`]::newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(string)
473 }
474 }
475
476 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'_ str> for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
477 fn fromrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<&str>`]from().(string: &str) -> Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<&str>`] {
478 Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`From<&str>`]::newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(string.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
479 }
480 }
481
482 impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
483 fn as_refrust-analyzer cargo debugid 0.8.0 impl#[CodeId][`AsRef<str>`]as_ref().(&self) -> &str {
484 self.as_strrust-analyzer cargo debugid 0.8.0 impl#[CodeId]as_str().()
485 }
486 }
487
488 impl strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
489 type Errrust-analyzer cargo debugid 0.8.0 impl#[CodeId][FromStr]Err# = ParseCodeIdErrorrust-analyzer cargo debugid 0.8.0 ParseCodeIdError#;
490
491 fn from_strrust-analyzer cargo debugid 0.8.0 impl#[CodeId][FromStr]from_str().(string: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][FromStr], ParseCodeIdErrorrust-analyzer cargo debugid 0.8.0 ParseCodeIdError#> {
492 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo debugid 0.8.0 impl#[CodeId][FromStr]::newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(string.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
493 }
494 }
495
496 #[cfg(feature = "serde")]
497 mod serde_supportrust-analyzer cargo debugid 0.8.0 serde_support/ {
498 use serderust-analyzer cargo serde 1.0.229 crate/::derust-analyzer cargo serde_core 1.0.229 de/::{selfrust-analyzer cargo serde_core 1.0.229 de/, Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#, Unexpectedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#, Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#};
499 use serderust-analyzer cargo serde 1.0.229 crate/::serrust-analyzer cargo serde_core 1.0.229 ser/::{Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#};
500
501 use superrust-analyzer cargo debugid 0.8.0 crate/::*;
502
503 impl Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
504 fn serializerust-analyzer cargo debugid 0.8.0 serde_support/impl#[CodeId][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> {
505 serializer.serialize_strrust-analyzer cargo serde_core 1.0.229 ser/Serializer#serialize_str().(self.as_strrust-analyzer cargo debugid 0.8.0 impl#[CodeId]as_str().())
506 }
507 }
508
509 impl<'de> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for CodeIdrust-analyzer cargo debugid 0.8.0 CodeId# {
510 fn deserializerust-analyzer cargo debugid 0.8.0 serde_support/impl#[CodeId][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 serde_support/impl#[CodeId][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> {
511 let string = 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().;
512 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CodeIdrust-analyzer cargo debugid 0.8.0 CodeId#::newrust-analyzer cargo debugid 0.8.0 impl#[CodeId]new().(string))
513 }
514 }
515
516 impl<'de> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
517 fn deserializerust-analyzer cargo debugid 0.8.0 serde_support/impl#[DebugId][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo debugid 0.8.0 serde_support/impl#[DebugId][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> {
518 struct Vrust-analyzer cargo debugid 0.8.0 serde_support/V#;
519
520 impl<'de> Visitorrust-analyzer cargo serde_core 1.0.229 de/Visitor#<'de> for Vrust-analyzer cargo debugid 0.8.0 serde_support/V# {
521 type Valuerust-analyzer cargo debugid 0.8.0 serde_support/impl#[V][`Visitor<'de>`]Value# = DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#;
522
523 fn expectingrust-analyzer cargo debugid 0.8.0 serde_support/impl#[V][`Visitor<'de>`]expecting().(&self, formatter: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::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# {
524 formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("DebugId")
525 }
526
527 fn visit_strrust-analyzer cargo debugid 0.8.0 serde_support/impl#[V][`Visitor<'de>`]visit_str().<E: derust-analyzer cargo serde_core 1.0.229 de/::Errorrust-analyzer cargo serde_core 1.0.229 de/Error#>(self, value: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<DebugIdrust-analyzer cargo debugid 0.8.0 DebugId#, E> {
528 value
529 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
530 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| derust-analyzer cargo serde_core 1.0.229 de/::Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::invalid_valuerust-analyzer cargo serde_core 1.0.229 de/Error#invalid_value().(Unexpectedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#::Strrust-analyzer cargo serde_core 1.0.229 de/Unexpected#Str#(value), &self))
531 }
532 }
533
534 deserializer.deserialize_strrust-analyzer cargo serde_core 1.0.229 de/Deserializer#deserialize_str().(Vrust-analyzer cargo debugid 0.8.0 serde_support/V#)
535 }
536 }
537
538 impl Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for DebugIdrust-analyzer cargo debugid 0.8.0 DebugId# {
539 fn serializerust-analyzer cargo debugid 0.8.0 serde_support/impl#[DebugId][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> {
540 serializer.serialize_strrust-analyzer cargo serde_core 1.0.229 ser/Serializer#serialize_str().(&self.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
541 }
542 }
543 }