pub struct ResourceBuilder { /* private fields */ }Expand description
Enhanced Resource Builder for type-safe resource construction.
This builder provides a fluent API for constructing SCIM resources with compile-time validation and type safety for all value objects.
§Example
use scim_server::Resource;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let user_data = json!({
"id": "123",
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"userName": "jdoe",
"name": {
"givenName": "John",
"familyName": "Doe"
},
"displayName": "John Doe"
});
let resource = Resource::from_json("User".to_string(), user_data)?;
Ok(())
}Implementations§
Source§impl ResourceBuilder
impl ResourceBuilder
Sourcepub fn new(resource_type: String) -> Self
pub fn new(resource_type: String) -> Self
Create a new ResourceBuilder with the specified resource type.
Sourcepub fn with_id(self, id: ResourceId) -> Self
pub fn with_id(self, id: ResourceId) -> Self
Set the resource ID.
Sourcepub fn with_external_id(self, external_id: ExternalId) -> Self
pub fn with_external_id(self, external_id: ExternalId) -> Self
Set the external ID.
Sourcepub fn with_username(self, username: UserName) -> Self
pub fn with_username(self, username: UserName) -> Self
Set the username (for User resources).
Sourcepub fn with_addresses(self, addresses: MultiValuedAddresses) -> Self
pub fn with_addresses(self, addresses: MultiValuedAddresses) -> Self
Set addresses for the resource.
Sourcepub fn with_phone_numbers(self, phone_numbers: MultiValuedPhoneNumbers) -> Self
pub fn with_phone_numbers(self, phone_numbers: MultiValuedPhoneNumbers) -> Self
Set phone numbers for the resource.
Sourcepub fn with_emails(self, emails: MultiValuedEmails) -> Self
pub fn with_emails(self, emails: MultiValuedEmails) -> Self
Set emails for the resource.
Sourcepub fn with_members(self, members: GroupMembers) -> Self
pub fn with_members(self, members: GroupMembers) -> Self
Set group members for the resource.
Sourcepub fn add_address(self, address: Address) -> Self
pub fn add_address(self, address: Address) -> Self
Add a single address to the resource.
Sourcepub fn add_phone_number(self, phone_number: PhoneNumber) -> Self
pub fn add_phone_number(self, phone_number: PhoneNumber) -> Self
Add a single phone number to the resource.
Sourcepub fn add_email(self, email: EmailAddress) -> Self
pub fn add_email(self, email: EmailAddress) -> Self
Add a single email to the resource.
Sourcepub fn add_schema(self, schema: SchemaUri) -> Self
pub fn add_schema(self, schema: SchemaUri) -> Self
Add a schema URI.
Sourcepub fn with_schemas(self, schemas: Vec<SchemaUri>) -> Self
pub fn with_schemas(self, schemas: Vec<SchemaUri>) -> Self
Set all schema URIs.
Sourcepub fn with_attribute<S: Into<String>>(self, name: S, value: Value) -> Self
pub fn with_attribute<S: Into<String>>(self, name: S, value: Value) -> Self
Add an extended attribute.
Sourcepub fn with_attributes(self, attributes: Map<String, Value>) -> Self
pub fn with_attributes(self, attributes: Map<String, Value>) -> Self
Add multiple extended attributes from a map.
Sourcepub fn build(self) -> ValidationResult<Resource>
pub fn build(self) -> ValidationResult<Resource>
Build the Resource.
Sourcepub fn build_with_meta(self, base_url: &str) -> ValidationResult<Resource>
pub fn build_with_meta(self, base_url: &str) -> ValidationResult<Resource>
Build the Resource and create meta attributes for a new resource.
Trait Implementations§
Source§impl Clone for ResourceBuilder
impl Clone for ResourceBuilder
Source§fn clone(&self) -> ResourceBuilder
fn clone(&self) -> ResourceBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ResourceBuilder
impl RefUnwindSafe for ResourceBuilder
impl Send for ResourceBuilder
impl Sync for ResourceBuilder
impl Unpin for ResourceBuilder
impl UnwindSafe for ResourceBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more