pub struct TenantId(/* private fields */);Expand description
Type-safe tenant identifier wrapper to prevent cross-tenant data leakage
This newtype provides compile-time guarantees that:
- Tenant IDs cannot be accidentally mixed with other string types
- All tenant-scoped operations explicitly require a TenantId
- Cross-tenant operations are caught at compile time
§Security
By making TenantId a distinct type, we enforce that all storage operations, queries, and business logic explicitly handle tenant isolation. This prevents entire classes of security vulnerabilities where tenant_id strings might be accidentally omitted, swapped, or compared incorrectly.
§Examples
use uvb_core::TenantId;
// Create a tenant ID
let tenant_id = TenantId::new("tenant_123");
// Access the inner value when needed
assert_eq!(tenant_id.as_str(), "tenant_123");
// Clone is cheap (wraps a String)
let cloned = tenant_id.clone();
assert_eq!(tenant_id, cloned);Implementations§
Source§impl TenantId
impl TenantId
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Get the tenant ID as a string slice
§Examples
use uvb_core::TenantId;
let tenant_id = TenantId::new("tenant_123");
assert_eq!(tenant_id.as_str(), "tenant_123");Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consume the TenantId and return the inner String
§Examples
use uvb_core::TenantId;
let tenant_id = TenantId::new("tenant_123");
let inner: String = tenant_id.into_inner();
assert_eq!(inner, "tenant_123");Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Validate that the tenant ID is well-formed
Returns true if the tenant ID:
- Is not empty
- Contains only alphanumeric characters, hyphens, and underscores
- Is between 1 and 255 characters long
§Examples
use uvb_core::TenantId;
assert!(TenantId::new("tenant_123").is_valid());
assert!(TenantId::new("tenant-abc-123").is_valid());
assert!(!TenantId::new("").is_valid());
assert!(!TenantId::new("tenant with spaces").is_valid());Trait Implementations§
Source§impl<'de> Deserialize<'de> for TenantId
impl<'de> Deserialize<'de> for TenantId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for TenantId
impl StructuralPartialEq for TenantId
Auto Trait Implementations§
impl Freeze for TenantId
impl RefUnwindSafe for TenantId
impl Send for TenantId
impl Sync for TenantId
impl Unpin for TenantId
impl UnsafeUnpin for TenantId
impl UnwindSafe for TenantId
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