pub struct RegistrationSource { /* private fields */ }Expand description
Source location for one linked registration.
§Examples
use qubit_validator::RegistrationSource;
let source = RegistrationSource::new("rules", "rules::text", "src/text.rs", 12);
assert_eq!(source.crate_name(), "rules");
assert_eq!(source.line(), 12);Implementations§
Source§impl RegistrationSource
impl RegistrationSource
Sourcepub const fn new(
crate_name: &'static str,
module_path: &'static str,
file: &'static str,
line: u32,
) -> Self
pub const fn new( crate_name: &'static str, module_path: &'static str, file: &'static str, line: u32, ) -> Self
Creates the source location of a validator registration.
crate_name, module_path, and file identify the declaring crate,
module, and source file, while line is the one-based source line.
All text fields must live for the duration of the program. This
constructor only stores the supplied metadata and does not access the
file system. It can be used for local registrations as well as the
registrations generated by register_validator!.
§Parameters
crate_name- Cargo package which declared the registration.module_path- Rust module path which declared the registration.file- Source file recorded at compile time.line- One-based source line recorded at compile time.
§Returns
Returns the source location containing the supplied metadata.
Examples found in repository?
examples/local_registry.rs (line 154)
150fn main() -> Result<(), Box<dyn Error>> {
151 let registration = ValidatorRegistration::new(
152 ValidatorId::new("text.non_blank"),
153 &DESCRIPTOR,
154 RegistrationSource::new(env!("CARGO_PKG_NAME"), module_path!(), file!(), line!()),
155 );
156 let registry = ValidatorRegistry::from_registrations([registration])?;
157
158 assert!(registry.get("text.non_blank").is_some());
159 let validator = registry.bind("text.non_blank", InputType::Text, &[])?;
160 let context = BoundValidationContext::new(&[]);
161
162 let valid = validator.validate(ValidationValue::Text("Ada"), &context)?;
163 assert_eq!(valid, ValidationOutcome::Valid);
164
165 let invalid = validator.validate(ValidationValue::Text(" "), &context)?;
166 let ValidationOutcome::Invalid(violations) = invalid else {
167 panic!("blank text must be invalid");
168 };
169 assert_eq!(violations.len(), 1);
170 assert_eq!(violations[0].code(), ViolationCode::new("text.blank"));
171
172 assert_dependency_specs_come_from_signature()?;
173 assert_parameters_are_consumed_once()?;
174
175 #[cfg(feature = "inventory")]
176 {
177 let global = ValidatorRegistry::try_global()?;
178 assert!(global.get("text.non_blank.global").is_some());
179 }
180
181 Ok(())
182}Sourcepub const fn crate_name(&self) -> &'static str
pub const fn crate_name(&self) -> &'static str
Returns the declaring crate name.
§Returns
Returns the Cargo package name stored in this source location.
Sourcepub const fn module_path(&self) -> &'static str
pub const fn module_path(&self) -> &'static str
Returns the declaring module path.
§Returns
Returns the Rust module path stored in this source location.
Trait Implementations§
Source§impl Clone for RegistrationSource
impl Clone for RegistrationSource
impl Copy for RegistrationSource
Source§impl Debug for RegistrationSource
impl Debug for RegistrationSource
impl Eq for RegistrationSource
Source§impl Ord for RegistrationSource
impl Ord for RegistrationSource
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 PartialEq for RegistrationSource
impl PartialEq for RegistrationSource
Source§impl PartialOrd for RegistrationSource
impl PartialOrd for RegistrationSource
impl StructuralPartialEq for RegistrationSource
Auto Trait Implementations§
impl Freeze for RegistrationSource
impl RefUnwindSafe for RegistrationSource
impl Send for RegistrationSource
impl Sync for RegistrationSource
impl Unpin for RegistrationSource
impl UnsafeUnpin for RegistrationSource
impl UnwindSafe for RegistrationSource
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