// Copyright 2013-2014 The Rust Project Developers. // Copyright 2018 The Uuid Project Developers. // // See the COPYRIGHT file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
/// Format a [`Uuid`] as a hyphenated string, like /// `67e55044-10b1-426f-9247-bb680e5fe0c8`. #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pubstruct Hyphenated(Uuid);
/// Format a [`Uuid`] as a simple string, like /// `67e5504410b1426f9247bb680e5fe0c8`. #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pubstruct Simple(Uuid);
/// Format a [`Uuid`] as a URN string, like /// `urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8`. #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pubstruct Urn(Uuid);
/// Format a [`Uuid`] as a braced hyphenated string, like /// `{67e55044-10b1-426f-9247-bb680e5fe0c8}`. #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] pubstruct Braced(Uuid);
impl Uuid { /// Get a [`Hyphenated`] formatter. #[inline] pubconstfn hyphenated(self) -> Hyphenated {
Hyphenated(self)
}
/// Get a borrowed [`Hyphenated`] formatter. #[inline] pubfn as_hyphenated(&self) -> &Hyphenated { // SAFETY: `Uuid` and `Hyphenated` have the same ABI unsafe { &*(selfas *const Uuid as *const Hyphenated) }
}
/// Get a [`Simple`] formatter. #[inline] pubconstfn simple(self) -> Simple {
Simple(self)
}
/// Get a borrowed [`Simple`] formatter. #[inline] pubfn as_simple(&self) -> &Simple { // SAFETY: `Uuid` and `Simple` have the same ABI unsafe { &*(selfas *const Uuid as *const Simple) }
}
/// Get a [`Urn`] formatter. #[inline] pubconstfn urn(self) -> Urn {
Urn(self)
}
/// Get a borrowed [`Urn`] formatter. #[inline] pubfn as_urn(&self) -> &Urn { // SAFETY: `Uuid` and `Urn` have the same ABI unsafe { &*(selfas *const Uuid as *const Urn) }
}
/// Get a [`Braced`] formatter. #[inline] pubconstfn braced(self) -> Braced {
Braced(self)
}
/// Get a borrowed [`Braced`] formatter. #[inline] pubfn as_braced(&self) -> &Braced { // SAFETY: `Uuid` and `Braced` have the same ABI unsafe { &*(selfas *const Uuid as *const Braced) }
}
}
letmut group_idx = 0; letmut i = 0; while group_idx < 5 { let (start, end) = groups[group_idx]; letmut j = start; while j < end { let x = src[i];
i += 1;
// SAFETY: `buf` is guaranteed to be at least `LEN` bytes // SAFETY: The encoded buffer is ASCII encoded unsafe {
ptr::write(dst.cast(), format_simple(src, upper));
str::from_utf8_unchecked_mut(buf)
}
}
// SAFETY: `buf` is guaranteed to be at least `LEN` bytes // SAFETY: The encoded buffer is ASCII encoded unsafe {
ptr::write(dst.cast(), format_hyphenated(src, upper));
str::from_utf8_unchecked_mut(buf)
}
}
impl Hyphenated { /// The length of a hyphenated [`Uuid`] string. /// /// [`Uuid`]: ../struct.Uuid.html pubconst LENGTH: usize = 36;
/// Creates a [`Hyphenated`] from a [`Uuid`]. /// /// [`Uuid`]: ../struct.Uuid.html /// [`Hyphenated`]: struct.Hyphenated.html pubconstfn from_uuid(uuid: Uuid) -> Self {
Hyphenated(uuid)
}
/// Writes the [`Uuid`] as a lower-case hyphenated string to /// `buffer`, and returns the subslice of the buffer that contains the /// encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.hyphenated() /// .encode_lower(&mut Uuid::encode_buffer()), /// "936da01f-9abd-4d9d-80c7-02af85c822a8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 40]; /// uuid.hyphenated().encode_lower(&mut buf); /// assert_eq!( /// &buf as &[_], /// b"936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_lower<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_hyphenated(self.0.as_bytes(), buffer, false)
}
/// Writes the [`Uuid`] as an upper-case hyphenated string to /// `buffer`, and returns the subslice of the buffer that contains the /// encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.hyphenated() /// .encode_upper(&mut Uuid::encode_buffer()), /// "936DA01F-9ABD-4D9D-80C7-02AF85C822A8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 40]; /// uuid.hyphenated().encode_upper(&mut buf); /// assert_eq!( /// &buf as &[_], /// b"936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_upper<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_hyphenated(self.0.as_bytes(), buffer, true)
}
/// Get a reference to the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let hyphenated = Uuid::nil().hyphenated(); /// assert_eq!(*hyphenated.as_uuid(), Uuid::nil()); /// ``` pubconstfn as_uuid(&self) -> &Uuid {
&self.0
}
/// Consumes the [`Hyphenated`], returning the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let hyphenated = Uuid::nil().hyphenated(); /// assert_eq!(hyphenated.into_uuid(), Uuid::nil()); /// ``` pubconstfn into_uuid(self) -> Uuid { self.0
}
}
impl Braced { /// The length of a braced [`Uuid`] string. /// /// [`Uuid`]: ../struct.Uuid.html pubconst LENGTH: usize = 38;
/// Creates a [`Braced`] from a [`Uuid`]. /// /// [`Uuid`]: ../struct.Uuid.html /// [`Braced`]: struct.Braced.html pubconstfn from_uuid(uuid: Uuid) -> Self {
Braced(uuid)
}
/// Writes the [`Uuid`] as a lower-case hyphenated string surrounded by /// braces to `buffer`, and returns the subslice of the buffer that contains /// the encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.braced() /// .encode_lower(&mut Uuid::encode_buffer()), /// "{936da01f-9abd-4d9d-80c7-02af85c822a8}" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 40]; /// uuid.braced().encode_lower(&mut buf); /// assert_eq!( /// &buf as &[_], /// b"{936da01f-9abd-4d9d-80c7-02af85c822a8}!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_lower<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_braced(self.0.as_bytes(), buffer, false)
}
/// Writes the [`Uuid`] as an upper-case hyphenated string surrounded by /// braces to `buffer`, and returns the subslice of the buffer that contains /// the encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.braced() /// .encode_upper(&mut Uuid::encode_buffer()), /// "{936DA01F-9ABD-4D9D-80C7-02AF85C822A8}" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 40]; /// uuid.braced().encode_upper(&mut buf); /// assert_eq!( /// &buf as &[_], /// b"{936DA01F-9ABD-4D9D-80C7-02AF85C822A8}!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_upper<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_braced(self.0.as_bytes(), buffer, true)
}
/// Get a reference to the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let braced = Uuid::nil().braced(); /// assert_eq!(*braced.as_uuid(), Uuid::nil()); /// ``` pubconstfn as_uuid(&self) -> &Uuid {
&self.0
}
/// Consumes the [`Braced`], returning the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let braced = Uuid::nil().braced(); /// assert_eq!(braced.into_uuid(), Uuid::nil()); /// ``` pubconstfn into_uuid(self) -> Uuid { self.0
}
}
impl Simple { /// The length of a simple [`Uuid`] string. /// /// [`Uuid`]: ../struct.Uuid.html pubconst LENGTH: usize = 32;
/// Creates a [`Simple`] from a [`Uuid`]. /// /// [`Uuid`]: ../struct.Uuid.html /// [`Simple`]: struct.Simple.html pubconstfn from_uuid(uuid: Uuid) -> Self {
Simple(uuid)
}
/// Writes the [`Uuid`] as a lower-case simple string to `buffer`, /// and returns the subslice of the buffer that contains the encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.simple().encode_lower(&mut Uuid::encode_buffer()), /// "936da01f9abd4d9d80c702af85c822a8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 36]; /// assert_eq!( /// uuid.simple().encode_lower(&mut buf), /// "936da01f9abd4d9d80c702af85c822a8" /// ); /// assert_eq!( /// &buf as &[_], /// b"936da01f9abd4d9d80c702af85c822a8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_lower<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_simple(self.0.as_bytes(), buffer, false)
}
/// Writes the [`Uuid`] as an upper-case simple string to `buffer`, /// and returns the subslice of the buffer that contains the encoded UUID. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.simple().encode_upper(&mut Uuid::encode_buffer()), /// "936DA01F9ABD4D9D80C702AF85C822A8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 36]; /// assert_eq!( /// uuid.simple().encode_upper(&mut buf), /// "936DA01F9ABD4D9D80C702AF85C822A8" /// ); /// assert_eq!( /// &buf as &[_], /// b"936DA01F9ABD4D9D80C702AF85C822A8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_upper<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_simple(self.0.as_bytes(), buffer, true)
}
/// Get a reference to the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let simple = Uuid::nil().simple(); /// assert_eq!(*simple.as_uuid(), Uuid::nil()); /// ``` pubconstfn as_uuid(&self) -> &Uuid {
&self.0
}
/// Consumes the [`Simple`], returning the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let simple = Uuid::nil().simple(); /// assert_eq!(simple.into_uuid(), Uuid::nil()); /// ``` pubconstfn into_uuid(self) -> Uuid { self.0
}
}
impl Urn { /// The length of a URN [`Uuid`] string. /// /// [`Uuid`]: ../struct.Uuid.html pubconst LENGTH: usize = 45;
/// Creates a [`Urn`] from a [`Uuid`]. /// /// [`Uuid`]: ../struct.Uuid.html /// [`Urn`]: struct.Urn.html pubconstfn from_uuid(uuid: Uuid) -> Self {
Urn(uuid)
}
/// Writes the [`Uuid`] as a lower-case URN string to /// `buffer`, and returns the subslice of the buffer that contains the /// encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.urn().encode_lower(&mut Uuid::encode_buffer()), /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 49]; /// uuid.urn().encode_lower(&mut buf); /// assert_eq!( /// uuid.urn().encode_lower(&mut buf), /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8" /// ); /// assert_eq!( /// &buf as &[_], /// b"urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_lower<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_urn(self.0.as_bytes(), buffer, false)
}
/// Writes the [`Uuid`] as an upper-case URN string to /// `buffer`, and returns the subslice of the buffer that contains the /// encoded UUID. /// /// This is slightly more efficient than using the formatting /// infrastructure as it avoids virtual calls, and may avoid /// double buffering. /// /// [`Uuid`]: ../struct.Uuid.html /// /// # Panics /// /// Panics if the buffer is not large enough: it must have length at least /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a /// sufficiently-large temporary buffer. /// /// [`LENGTH`]: #associatedconstant.LENGTH /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// fn main() -> Result<(), uuid::Error> { /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?; /// /// // the encoded portion is returned /// assert_eq!( /// uuid.urn().encode_upper(&mut Uuid::encode_buffer()), /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8" /// ); /// /// // the buffer is mutated directly, and trailing contents remains /// let mut buf = [b'!'; 49]; /// assert_eq!( /// uuid.urn().encode_upper(&mut buf), /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8" /// ); /// assert_eq!( /// &buf as &[_], /// b"urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_] /// ); /// /// Ok(()) /// } /// ``` /// */ #[inline] pubfn encode_upper<'buf>(&self, buffer: &'buf mut [u8]) -> &'buf mut str {
encode_urn(self.0.as_bytes(), buffer, true)
}
/// Get a reference to the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let urn = Uuid::nil().urn(); /// assert_eq!(*urn.as_uuid(), Uuid::nil()); /// ``` pubconstfn as_uuid(&self) -> &Uuid {
&self.0
}
/// Consumes the [`Urn`], returning the underlying [`Uuid`]. /// /// # Examples /// /// ```rust /// use uuid::Uuid; /// /// let urn = Uuid::nil().urn(); /// assert_eq!(urn.into_uuid(), Uuid::nil()); /// ``` pubconstfn into_uuid(self) -> Uuid { self.0
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.