@@ -42,6 +42,38 @@ If the client will be exposed over WASM, annotate both the struct and its `impl`
4242#[cfg_attr(feature = " wasm" , wasm_bindgen)]
4343```
4444
45+ ### UniFFI wrappers
46+
47+ Mobile clients access the SDK through thin wrapper structs in the ` bitwarden-uniffi ` crate. Each
48+ wrapper holds a ` SharedClient ` (a type alias for ` Arc<Client> ` ) and delegates to the underlying Rust
49+ client:
50+
51+ ``` rust
52+ pub struct FoldersClient (pub (crate ) SharedClient );
53+
54+ #[uniffi:: export]
55+ impl FoldersClient {
56+ pub async fn get (& self , folder_id : FolderId ) -> Result <FolderView > {
57+ Ok (self . 0. vault (). folders (). get (folder_id ). await ? )
58+ }
59+ }
60+ ```
61+
62+ The wrapper mirrors the structure of the Rust client hierarchy — parent wrappers expose child
63+ wrappers through accessor methods, just like the application interface clients do. For example, a
64+ ` VaultClient ` wrapper returns ` Arc<FoldersClient> ` .
65+
66+ #### Error conversion
67+
68+ UniFFI wrappers use a crate-level ` Result<T> ` type alias that maps errors to ` BitwardenError ` . This
69+ ensures all errors crossing the FFI boundary are converted into a type that UniFFI can serialize for
70+ Kotlin and Swift consumers. Use the ` ? ` operator in wrapper methods to automatically convert
71+ domain-specific errors through the ` From<E> for BitwardenError ` implementations.
72+
73+ When introducing a new error type, add a variant for it in
74+ [ ` bitwarden-uniffi/src/error.rs ` ] [ uniffi-error ] and implement the ` From ` conversion so it can be
75+ propagated with ` ? ` .
76+
4577## Extension traits
4678
4779Feature crates connect to the SDK ` Client ` through extension traits. This keeps feature code
@@ -188,3 +220,6 @@ async fn test_get_folder_not_found() {
188220 assert! (matches! (result . unwrap_err (), GetFolderError :: ItemNotFound (_ )));
189221}
190222```
223+
224+ [ uniffi-error] :
225+ https://github.com/bitwarden/sdk-internal/blob/main/crates/bitwarden-uniffi/src/error.rs
0 commit comments