pub struct Code(/* private fields */);Expand description
A stable diagnostic code, rendered as Y####.
use oneyaml_core::code::{self, CodeRange};
use oneyaml_core::{Code, Severity};
let c = Code::parse("Y1014").unwrap();
assert_eq!(c, code::DUPLICATE_KEY_LAST_WINS);
assert_eq!((c.get(), c.to_string()), (1014, "Y1014".to_owned()));
assert_eq!(c.range(), CodeRange::Schema);
assert_eq!(CodeRange::Schema.bounds(), (1000, 1999));
let info = c.info().unwrap(); // the registry entry
assert_eq!(info.name, "DUPLICATE_KEY_LAST_WINS");
assert_eq!(info.severity, Severity::Warning);
assert!(Code::parse("Y0000").is_none()); // Y0000 is never used
assert_eq!(format!("{c:?}"), "Y1014"); // `Debug` shows the same formImplementations§
Source§impl Code
impl Code
Sourcepub const fn new(n: u16) -> Option<Self>
pub const fn new(n: u16) -> Option<Self>
Returns the code with number n, or None if n lies outside every
allocated range (including 0).
This validates the range only and exists for parsing, deserializing, and tests. Library code never calls it: it emits only the registered constants in this module, which a test enforces by scanning the library crates’ sources.
Trait Implementations§
impl Copy for Code
impl Eq for Code
Source§impl Ord for Code
impl Ord for Code
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Code
impl PartialOrd for Code
impl StructuralPartialEq for Code
Auto Trait Implementations§
impl Freeze for Code
impl RefUnwindSafe for Code
impl Send for Code
impl Sync for Code
impl Unpin for Code
impl UnsafeUnpin for Code
impl UnwindSafe for Code
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more