Skip to content

Commit ba210e7

Browse files
committed
Impl new, From, FromStr for Uuid
1 parent 459bde4 commit ba210e7

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

crates/bitwarden-uniffi/src/vault/ciphers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl CiphersClient {
4141
) -> Result<CipherView> {
4242
Ok(self
4343
.0
44-
.move_to_organization(cipher, OrganizationId(organization_id))
44+
.move_to_organization(cipher, OrganizationId::new(organization_id))
4545
.map_err(Error::Cipher)?)
4646
}
4747
}

crates/bitwarden-uuid-macro/src/lib.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,38 @@ pub fn uuid(input: TokenStream) -> TokenStream {
2222
#[repr(transparent)]
2323
#vis struct #ident(
2424
#[tsify(type = #tsify_type)]
25-
pub uuid::Uuid
25+
uuid::Uuid
2626
);
2727

2828
#[cfg(not(feature = "wasm"))]
2929
#[derive(serde::Serialize, serde::Deserialize)]
3030
#[repr(transparent)]
3131
#vis struct #ident(
32-
pub uuid::Uuid
32+
uuid::Uuid
3333
);
3434

3535
#[cfg(feature = "uniffi")]
3636
uniffi::custom_newtype!(#ident, uuid::Uuid);
37+
38+
impl #ident {
39+
pub fn new(value: uuid::Uuid) -> Self {
40+
Self(value)
41+
}
42+
}
43+
44+
impl std::str::FromStr for #ident {
45+
type Err = uuid::Error;
46+
47+
fn from_str(s: &str) -> Result<Self, Self::Err> {
48+
uuid::Uuid::from_str(s).map(Self)
49+
}
50+
}
51+
52+
impl From<#ident> for uuid::Uuid {
53+
fn from(value: #ident) -> Self {
54+
value.0
55+
}
56+
}
3757
};
3858

3959
TokenStream::from(expanded)

crates/bitwarden-vault/src/cipher/cipher_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl CiphersClient {
6464
organization_id: OrganizationId,
6565
) -> Result<CipherView, CipherError> {
6666
let key_store = self.client.internal.get_key_store();
67-
cipher_view.move_to_organization(&mut key_store.context(), organization_id.0)?;
67+
cipher_view.move_to_organization(&mut key_store.context(), organization_id.into())?;
6868
Ok(cipher_view)
6969
}
7070

0 commit comments

Comments
 (0)