#![feature(prelude_import)]
#![doc(html_root_url = "https://docs.rs/fixed_len_str_example/0.1.8/")]
#![no_std]
//! This crate contains an example of the struct generated by the procedural macro contained in [fixed_len_str],use that
//! macro instead.
#[prelude_import]
use core::prelude::v1::*;
#[macro_use]
extern crate core;
#[macro_use]
extern crate compiler_builtins;
pub mod fixed_str12 {
    extern crate alloc;
    use alloc::string::String;
    use alloc::vec::Vec;
    use core::fmt::{Debug, Display, Formatter, Result as FmtResult};
    use core::ops::{Deref, DerefMut};
    use core::convert::{AsRef, AsMut};
    use core::hash::{Hasher, Hash};
    use core::borrow::{Borrow, BorrowMut};
    use core::cmp::Ordering;
    use core::default::Default;
    use core::str::Utf8Error;
    /// A fixed length string with a length of 12.
    #[repr(transparent)]
    pub struct FixedStr12 {
        pub array: [u8; 12],
    }
    #[automatically_derived]
    #[allow(unused_qualifications)]
    impl ::core::clone::Clone for FixedStr12 {
        #[inline]
        fn clone(&self) -> FixedStr12 {
            match *self {
                FixedStr12 {
                    array: ref __self_0_0,
                } => FixedStr12 {
                    array: ::core::clone::Clone::clone(&(*__self_0_0)),
                },
            }
        }
    }
    impl FixedStr12 {
        /// Creates an FixedStr12 from an array,returning an error at invalid utf8.
        #[inline]
        pub fn new(array: [u8; 12]) -> Result<Self, Utf8Error> {
            let mut index = 0;
            for (i, e) in (&array[..]).iter().rev().enumerate() {
                if *e != 0 {
                    index = 12 - i;
                    break;
                }
            }
            core::str::from_utf8(&array[..index])?;
            Ok(Self { array })
        }
        /// Creates an FixedStr12 without checking if the bytes are valid utf8.
        ///
        /// # Safety
        ///
        /// Ensure to only use this method with valid utf8.
        #[inline]
        pub const unsafe fn new_unchecked(array: [u8; 12]) -> Self {
            Self { array }
        }
        /// Borrow the internal array as an slice.
        #[inline]
        pub fn as_bytes(&self) -> &[u8] {
            &self.array[..]
        }
        /// Borrow the internal array as a mutable slice.
        ///
        /// # Safety
        ///
        /// This is unsafe due to allow modifications that can produce invalid utf8.
        #[inline]
        pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
            &mut self.array[..]
        }
        /// Fill the last spaces in zero of the buffer with a determinated character.Useful when constructing the array with all bytes in
        /// zero and then filling them in an incremental way.
        ///
        /// # Panics
        ///
        /// This will panic on debug if the zero spaces are not sufficient for the non-zero spaces of the character interpreted as
        /// `\[u8; 4\]`.
        #[inline]
        pub fn fill_char(&mut self, character: char) {
            let position = self.array.iter().position(|e| *e == 0u8).unwrap_or(12);
            let character = unsafe { core::mem::transmute::<char, [u8; 4]>(character) };
            if true {
                if !((&self.array[position..]).len()
                    >= character.iter().position(|e| *e == 0u8).unwrap_or(4))
                {
                    :: core :: panicking :: panic ( "assertion failed: (&self.array[position..]).len() >=\n    character.iter().position(|e| *e == 0u8).unwrap_or(4)" )
                };
            };
            for (e, c) in self.array[position..].iter_mut().zip(character.iter()) {
                *e = *c;
            }
        }
        /// Fill the last spaces in zero of the buffer with a determinated string.Useful when constructing the array with all bytes in
        /// zero and then filling them in an incremental way.
        ///
        /// # Panics
        ///
        /// This will panic on debug if the zero spaces are not sufficient for the non-zero spaces of the string interpreted as
        /// `&\[u8\]`.
        #[inline]
        pub fn fill_str(&mut self, s: &str) {
            let position = self.array.iter().position(|e| *e == 0u8).unwrap_or(12);
            if true {
                if !((&self.array[position..]).len()
                    >= s.as_bytes()
                        .iter()
                        .position(|e| *e == 0u8)
                        .unwrap_or(s.len()))
                {
                    :: core :: panicking :: panic ( "assertion failed: (&self.array[position..]).len() >=\n    s.as_bytes().iter().position(|e| *e == 0u8).unwrap_or(s.len())" )
                };
            };
            for (e, c) in self.array[position..].iter_mut().zip(s.as_bytes().iter()) {
                *e = *c;
            }
        }
        /// Convert the FixedStr12 into a vector of bytes.
        #[inline]
        pub fn into_vec(self) -> Vec<u8> {
            let arr = core::mem::ManuallyDrop::new(self.array);
            let mut buf = Vec::with_capacity(12);
            unsafe {
                arr.as_ptr().copy_to(buf.as_mut_ptr(), 12);
                buf.set_len(12)
            }
            buf
        }
        /// Turn the FixedStr12 into a string,moving the bytes.
        #[inline]
        pub fn into_string(self) -> String {
            let mut vec = core::mem::ManuallyDrop::new(self.into_vec());
            unsafe { String::from_raw_parts(vec.as_mut_ptr(), vec.len(), vec.capacity()) }
        }
        /// Construct a FixedStr12 from a vector of bytes,truncating or pushing zeroes to adjust the size to 12.
        ///
        /// Using this function with multi-byte characters can easely produce an unexpected value.
        #[inline]
        pub fn from_vec(mut vec: Vec<u8>) -> FixedStr12 {
            use core::mem::{transmute, MaybeUninit};
            vec.resize(12, 0);
            let mut array = [MaybeUninit::uninit(); 12];
            let vec = unsafe { transmute::<Vec<u8>, Vec<MaybeUninit<u8>>>(vec) };
            unsafe { vec.as_ptr().copy_to(array.as_mut_ptr(), 12) };
            core::mem::forget(vec);
            Self {
                array: unsafe { transmute(array) },
            }
        }
        /// Construct a FixedStr12 from a String,truncating or pushing zeroes to adjust the size to 12.
        ///
        /// Using this function with multi-byte characters can easely produce an unexpected value.
        #[inline]
        pub fn from_string(string: String) -> FixedStr12 {
            Self::from_vec(string.into_bytes())
        }
        /// Construct a FixedStr12 from a str,without checking if it has length 12.
        ///
        /// # Safety
        ///
        /// This will trigger UB on str's with length different than 12.
        #[inline]
        pub unsafe fn from_str_unchecked(s: &str) -> FixedStr12 {
            Self::new_unchecked(*core::mem::transmute_copy::<&'_ [u8], &'_ [u8; 12]>(
                &s.as_bytes(),
            ))
        }
    }
    impl Default for FixedStr12 {
        fn default() -> Self {
            Self { array: [0; 12] }
        }
    }
    impl Display for FixedStr12 {
        fn fmt(&self, f: &'_ mut Formatter) -> FmtResult {
            f.write_fmt(::core::fmt::Arguments::new_v1(
                &[""],
                &match (&self.as_ref(),) {
                    (arg0,) => [::core::fmt::ArgumentV1::new(
                        arg0,
                        ::core::fmt::Display::fmt,
                    )],
                },
            ))
        }
    }
    impl Debug for FixedStr12 {
        fn fmt(&self, f: &mut Formatter) -> FmtResult {
            f.write_fmt(::core::fmt::Arguments::new_v1(
                &[""],
                &match (&self,) {
                    (arg0,) => [::core::fmt::ArgumentV1::new(
                        arg0,
                        ::core::fmt::Display::fmt,
                    )],
                },
            ))
        }
    }
    impl Deref for FixedStr12 {
        type Target = str;
        #[inline]
        fn deref(&self) -> &Self::Target {
            let mut index = 0;
            for (i, e) in self.as_bytes().iter().rev().enumerate() {
                if *e != 0 {
                    index = 12 - i;
                    break;
                }
            }
            unsafe { core::str::from_utf8_unchecked(&self.array[..index]) }
        }
    }
    impl DerefMut for FixedStr12 {
        #[inline]
        fn deref_mut(&mut self) -> &mut Self::Target {
            let mut index = 0;
            for (i, e) in self.as_bytes().iter().rev().enumerate() {
                if *e != 0 {
                    index = 12 - i;
                    break;
                }
            }
            unsafe { core::str::from_utf8_unchecked_mut(&mut self.array[..index]) }
        }
    }
    impl AsRef<str> for FixedStr12 {
        fn as_ref(&self) -> &str {
            <Self as Deref>::deref(self)
        }
    }
    impl AsMut<str> for FixedStr12 {
        fn as_mut(&mut self) -> &mut str {
            <Self as DerefMut>::deref_mut(self)
        }
    }
    impl From<&str> for FixedStr12 {
        /// Construct a FixedStr12 from a str,if it is greater it take 12 bytes,if it is smaller it
        /// will leave the remanining spaces of the FixedStr12 in zero.
        ///
        /// # Panics
        ///
        /// This will panic if the length of `s` is greater than 12 on debug.
        #[inline]
        fn from(s: &str) -> Self {
            if s.len() == 12 {
                unsafe { Self::from_str_unchecked(s) }
            } else if s.len() < 12 {
                let mut fixed_str = FixedStr12::default();
                fixed_str.fill_str(s);
                fixed_str
            } else if true {
                ::core::panicking::panic("the length of the string was greater than 12 on debug")
            } else {
                unsafe { Self::from_str_unchecked(&s[..12]) }
            }
        }
    }
    impl From<Vec<u8>> for FixedStr12 {
        fn from(v: Vec<u8>) -> Self {
            Self::from_vec(v)
        }
    }
    impl From<String> for FixedStr12 {
        fn from(s: String) -> Self {
            Self::from_string(s)
        }
    }
    impl PartialEq<str> for FixedStr12 {
        #[inline]
        fn eq(&self, other: &str) -> bool {
            self.as_ref() == other
        }
    }
    impl PartialEq<&str> for FixedStr12 {
        #[inline]
        fn eq(&self, other: &&str) -> bool {
            self.as_ref() == *other
        }
    }
    impl PartialEq for FixedStr12 {
        #[inline]
        fn eq(&self, other: &Self) -> bool {
            self.as_ref() == other.as_ref()
        }
    }
    impl Eq for FixedStr12 {}
    impl Hash for FixedStr12 {
        fn hash<H: Hasher>(&self, state: &mut H) {
            self.as_ref().hash(state)
        }
    }
    impl Borrow<str> for FixedStr12 {
        fn borrow(&self) -> &str {
            self.as_ref()
        }
    }
    impl BorrowMut<str> for FixedStr12 {
        fn borrow_mut(&mut self) -> &mut str {
            self.as_mut()
        }
    }
    impl PartialOrd for FixedStr12 {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
            self.as_ref().partial_cmp(other.as_ref())
        }
    }
    impl Ord for FixedStr12 {
        fn cmp(&self, other: &Self) -> Ordering {
            self.as_ref().cmp(other.as_ref())
        }
    }
    use serde::{Serialize, Deserialize, Serializer, Deserializer};
    use serde::de;
    /// Only expanded in the original crate with the feature "serde_support" enabled.
    impl Serialize for FixedStr12 {
        fn serialize<S: Serializer>(&'_ self, serializer: S) -> Result<S::Ok, S::Error> {
            serializer.serialize_str(self.as_ref())
        }
    }
    struct FixedStr12Visitor;
    impl<'de> de::Visitor<'de> for FixedStr12Visitor {
        type Value = FixedStr12;
        fn expecting<'a>(&'a self, formatter: &'a mut Formatter) -> FmtResult {
            formatter.write_str("a string less or equal to 12 bytes")
        }
        fn visit_str<E: de::Error>(self, s: &'_ str) -> Result<Self::Value, E> {
            if s.len() <= 12 {
                Ok(FixedStr12::from(s))
            } else {
                Err(de::Error::invalid_value(de::Unexpected::Str(s), &self))
            }
        }
    }
    /// Only expanded in the original crate with the feature "serde_support" enabled.
    impl<'de> Deserialize<'de> for FixedStr12 {
        fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
            deserializer.deserialize_str(FixedStr12Visitor)
        }
    }
}
pub use fixed_str12::FixedStr12;
pub mod fixed_str_nz12 {
    extern crate alloc;
    use alloc::string::String;
    use alloc::vec::Vec;
    use core::fmt::{Debug, Display, Formatter, Result as FmtResult};
    use core::ops::{Deref, DerefMut};
    use core::borrow::{Borrow, BorrowMut};
    use core::convert::{AsRef, AsMut};
    use core::hash::{Hasher, Hash};
    use core::cmp::Ordering;
    use core::str::Utf8Error;
    use core::num::NonZeroU8;
    use core::mem::{transmute, transmute_copy};
    /// A fixed length string with a length of 12.
    #[repr(transparent)]
    pub struct FixedStrNZ12 {
        pub array: [NonZeroU8; 12],
    }
    #[automatically_derived]
    #[allow(unused_qualifications)]
    impl ::core::clone::Clone for FixedStrNZ12 {
        #[inline]
        fn clone(&self) -> FixedStrNZ12 {
            match *self {
                FixedStrNZ12 {
                    array: ref __self_0_0,
                } => FixedStrNZ12 {
                    array: ::core::clone::Clone::clone(&(*__self_0_0)),
                },
            }
        }
    }
    impl FixedStrNZ12 {
        /// Creates an FixedStrNZ12 from an array,returning an error at invalid utf8.
        #[inline]
        pub fn new(array: [NonZeroU8; 12]) -> Result<Self, Utf8Error> {
            let fixed_str = Self { array };
            core::str::from_utf8(fixed_str.as_bytes())?;
            Ok(fixed_str)
        }
        /// Creates an FixedStrNZ12 without checking if the bytes are valid utf8.
        ///
        /// # Safety
        ///
        /// Ensure to only use this method with valid utf8.
        #[inline]
        pub const unsafe fn new_unchecked(array: [NonZeroU8; 12]) -> Self {
            Self { array }
        }
        /// Borrow the internal array as an slice.
        #[inline]
        pub fn as_bytes(&self) -> &[u8] {
            unsafe { transmute(&self.array[..]) }
        }
        /// Borrow the internal array as a mutable slice.
        ///
        /// # Safety
        ///
        /// This is unsafe due to allow modifications that can produce invalid utf8.
        #[inline]
        pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
            transmute(&mut self.array[..])
        }
        /// Convert the FixedStrNZ12 into a vector of bytes.
        #[inline]
        pub fn into_vec(self) -> Vec<NonZeroU8> {
            let arr = core::mem::ManuallyDrop::new(self.array);
            let mut buf: Vec<NonZeroU8> = Vec::with_capacity(12);
            unsafe {
                arr.as_ptr().copy_to(buf.as_mut_ptr(), 12);
                buf.set_len(12)
            }
            buf
        }
        /// Turn the FixedStrNZ12 into a string,moving the bytes.
        #[inline]
        pub fn into_string(self) -> String {
            let mut vec = core::mem::ManuallyDrop::new(self.into_vec());
            unsafe {
                String::from_raw_parts(vec.as_mut_ptr() as *mut u8, vec.len(), vec.capacity())
            }
        }
        /// Construct a FixedStrNZ12 from a vector of bytes,truncating to adjust the size to 12.
        ///
        /// Using this function with multi-byte characters can easely produce an unexpected value.
        ///
        /// # Panics
        ///
        /// This function will panic if the length is less than 12.
        #[inline]
        pub fn from_vec(mut vec: Vec<NonZeroU8>) -> FixedStrNZ12 {
            use core::mem::MaybeUninit;
            if !(vec.len() >= 12) {
                ::core::panicking::panic("assertion failed: vec.len() >= 12")
            };
            vec.truncate(12);
            let mut array: [MaybeUninit<NonZeroU8>; 12] = [MaybeUninit::uninit(); 12];
            let vec: Vec<MaybeUninit<NonZeroU8>> = unsafe { transmute(vec) };
            unsafe { vec.as_ptr().copy_to(array.as_mut_ptr(), 12) };
            core::mem::forget(vec);
            Self {
                array: unsafe { transmute::<[MaybeUninit<NonZeroU8>; 12], [NonZeroU8; 12]>(array) },
            }
        }
        /// Construct a FixedStrNZ12 from a String,truncating to adjust the size to 12.
        ///
        /// Using this function with multi-byte characters can easely produce an unexpected value.
        #[inline]
        pub fn from_string(string: String) -> FixedStrNZ12 {
            Self::from_vec(unsafe { transmute(string.into_bytes()) })
        }
        /// Construct a FixedStrNZ12 from a str,without checking if it has length 12.
        ///
        /// # Safety
        ///
        /// This will trigger UB on str's with length different than 12.
        #[inline]
        pub unsafe fn from_str_unchecked(s: &str) -> FixedStrNZ12 {
            Self::new_unchecked(*core::mem::transmute_copy::<&'_ [u8], &'_ [NonZeroU8; 12]>(
                &s.as_bytes(),
            ))
        }
    }
    impl Display for FixedStrNZ12 {
        fn fmt(&self, f: &'_ mut Formatter) -> FmtResult {
            f.write_fmt(::core::fmt::Arguments::new_v1(
                &[""],
                &match (&self.as_ref(),) {
                    (arg0,) => [::core::fmt::ArgumentV1::new(
                        arg0,
                        ::core::fmt::Display::fmt,
                    )],
                },
            ))
        }
    }
    impl Debug for FixedStrNZ12 {
        fn fmt(&self, f: &mut Formatter) -> FmtResult {
            f.write_fmt(::core::fmt::Arguments::new_v1(
                &[""],
                &match (&self,) {
                    (arg0,) => [::core::fmt::ArgumentV1::new(
                        arg0,
                        ::core::fmt::Display::fmt,
                    )],
                },
            ))
        }
    }
    impl Deref for FixedStrNZ12 {
        type Target = str;
        #[inline]
        fn deref(&self) -> &Self::Target {
            unsafe { core::str::from_utf8_unchecked(self.as_bytes()) }
        }
    }
    impl DerefMut for FixedStrNZ12 {
        #[inline]
        fn deref_mut(&mut self) -> &mut Self::Target {
            unsafe { core::str::from_utf8_unchecked_mut(self.as_bytes_mut()) }
        }
    }
    impl AsRef<str> for FixedStrNZ12 {
        fn as_ref(&self) -> &str {
            <Self as Deref>::deref(self)
        }
    }
    impl AsMut<str> for FixedStrNZ12 {
        fn as_mut(&mut self) -> &mut str {
            <Self as DerefMut>::deref_mut(self)
        }
    }
    impl From<&str> for FixedStrNZ12 {
        /// Construct a FixedStrNZ12 from a string of length greater or equal to 12,if it is
        /// greater will take 12 bytes so be careful with no ascii letters.
        ///
        /// # Panics
        ///
        /// This will panic if the length of `s` is less than 12 and if it is greater on debug.
        #[inline]
        fn from(s: &str) -> Self {
            if s.len() == 12 {
                unsafe { Self::from_str_unchecked(s) }
            } else if s.len() > 12 {
                if true {
                    ::core::panicking::panic(
                        "the length of the string was greater than 12 on debug",
                    )
                }
                unsafe { Self::from_str_unchecked(s) }
            } else {
                ::core::panicking::panic("the length of the string was less than 12")
            }
        }
    }
    impl From<Vec<NonZeroU8>> for FixedStrNZ12 {
        fn from(v: Vec<NonZeroU8>) -> Self {
            Self::from_vec(v)
        }
    }
    impl From<String> for FixedStrNZ12 {
        fn from(s: String) -> Self {
            Self::from_string(s)
        }
    }
    impl PartialEq<str> for FixedStrNZ12 {
        fn eq(&self, other: &str) -> bool {
            self.as_ref() == other
        }
    }
    impl PartialEq<&str> for FixedStrNZ12 {
        fn eq(&self, other: &&str) -> bool {
            self.as_ref() == *other
        }
    }
    impl PartialEq for FixedStrNZ12 {
        fn eq(&self, other: &Self) -> bool {
            self.as_ref() == other.as_ref()
        }
    }
    impl Eq for FixedStrNZ12 {}
    impl Hash for FixedStrNZ12 {
        fn hash<H: Hasher>(&self, state: &mut H) {
            self.as_ref().hash(state)
        }
    }
    impl Borrow<str> for FixedStrNZ12 {
        fn borrow(&self) -> &str {
            self.as_ref()
        }
    }
    impl BorrowMut<str> for FixedStrNZ12 {
        fn borrow_mut(&mut self) -> &mut str {
            self.as_mut()
        }
    }
    impl PartialOrd for FixedStrNZ12 {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
            self.as_ref().partial_cmp(other.as_ref())
        }
    }
    impl Ord for FixedStrNZ12 {
        fn cmp(&self, other: &Self) -> Ordering {
            self.as_ref().cmp(other.as_ref())
        }
    }
    use serde::{Serialize, Deserialize, Serializer, Deserializer};
    use serde::de;
    /// Only expanded in the original crate with the feature "serde_support" enabled.
    impl Serialize for FixedStrNZ12 {
        fn serialize<S: Serializer>(&'_ self, serializer: S) -> Result<S::Ok, S::Error> {
            serializer.serialize_str(self.as_ref())
        }
    }
    struct FixedStrNZ12Visitor;
    impl<'de> de::Visitor<'de> for FixedStrNZ12Visitor {
        type Value = FixedStrNZ12;
        fn expecting<'a>(&'a self, formatter: &'a mut Formatter) -> FmtResult {
            formatter.write_str("a string containing exactly 12 bytes")
        }
        fn visit_str<E: de::Error>(self, s: &'_ str) -> Result<Self::Value, E> {
            if s.len() == 12 {
                Ok(FixedStrNZ12::from(s))
            } else {
                Err(de::Error::invalid_value(de::Unexpected::Str(s), &self))
            }
        }
    }
    /// Only expanded in the original crate with the feature "serde_support" enabled.
    impl<'de> Deserialize<'de> for FixedStrNZ12 {
        fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
            deserializer.deserialize_str(FixedStrNZ12Visitor)
        }
    }
}
pub use fixed_str_nz12::FixedStrNZ12;
