🪪 id_newtype
Implements logic for a Cow<'static, str> newtype where only [A-Za-z0-9_] are valid characters.
Implementations are provided for:
IdType::newIdType::new_unchecked(with#[doc(hidden)])IdType::is_valid_idIdType::into_innerstd::borrow::Borrow<str>std::convert::AsRef<str>std::convert::TryFrom<String>std::convert::TryFrom<&'static str>std::fmt::Displaystd::ops::Derefstd::ops::DerefMutstd::str::FromStr
A separate error type is also generated, which indicates an invalid value when the ID type is instantiated with new.
Usage
use Cow;
// Rename your ID type
;
crateid_newtype!;
If you have a procedural macro that checks for ID validity1 at compile time, you may pass in its name as follows:
use Cow;
// replace this with your ID type's macro
use my_id_type;
// Rename your ID type
;
crateid_newtype!;
1 This crate was extracted from peace, so the my_crate_static_check_macros is not generated for you. You must implement it yourself. See static_check_macros for an example.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.