pub struct LicenseValidator { /* private fields */ }Expand description
License validator that checks keys against the API with caching.
The validator implements a multi-tier validation strategy:
- Check key format (must start with
sub_) - Check local cache for fresh result
- Call API if cache is stale or missing
- Fall back to stale cache if network fails
§Examples
ⓘ
use logicaffeine_verify::LicenseValidator;
let validator = LicenseValidator::new();
// Validate a license key
match validator.validate("sub_abc123") {
Ok(plan) => {
if plan.can_verify() {
println!("Verification enabled with {} plan", plan);
}
}
Err(e) => eprintln!("License error: {}", e),
}Implementations§
Source§impl LicenseValidator
impl LicenseValidator
Sourcepub fn validate(&self, key: &str) -> VerificationResult<LicensePlan>
pub fn validate(&self, key: &str) -> VerificationResult<LicensePlan>
Validate a license key.
Returns the license plan if valid and verification-capable. Returns an error if the key is invalid, the plan doesn’t include verification, or network validation fails.
§Validation Steps
- Format check: Key must start with
sub_ - Cache check: Return cached result if < 24 hours old
- API call: Validate against
api.logicaffeine.com - Fallback: Use stale cache if network fails
§Errors
LicenseInvalid- Key format is wrong or API rejected itLicenseInsufficientPlan- License valid but plan lacks verification
§Examples
ⓘ
use logicaffeine_verify::LicenseValidator;
let validator = LicenseValidator::new();
// Invalid format
assert!(validator.validate("invalid").is_err());
// Valid key (requires network)
let result = validator.validate("sub_abc123");Trait Implementations§
Auto Trait Implementations§
impl Freeze for LicenseValidator
impl RefUnwindSafe for LicenseValidator
impl Send for LicenseValidator
impl Sync for LicenseValidator
impl Unpin for LicenseValidator
impl UnsafeUnpin for LicenseValidator
impl UnwindSafe for LicenseValidator
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