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::{ResourceBuilder, ResourceId, UserName, Name};
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resource = ResourceBuilder::new("User".to_string())
.with_id(ResourceId::new("123".to_string())?)
.with_username(UserName::new("jdoe".to_string())?)
.with_name(Name::new_simple("John".to_string(), "Doe".to_string())?)
.with_attribute("displayName", json!("John Doe"))
.build()?;
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 more