Sample code for 30+ languages & platforms
Rust

Create or Update a Secret from the Content of a StringBuilder

See more Secrets Examples

Create or update a secret from the content of a Chilkat StringBuilder object.

Note: This example requires Chilkat v10.1.0 or later.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let secrets = chilkat::Secrets::new();

// On Windows, this is the Windows Credentials Manager
// On MacOS/iOS, it is the Apple Keychain
secrets.set_location("local_manager");

// Specify the name of the secret.
// service and username are required.
// appName and domain are optional.
// Note: The values are arbitrary and can be anything you want.
let json = chilkat::JsonObject::new();
let _ = json.update_string("appName", "Test");
let _ = json.update_string("service", "MyService");
let _ = json.update_string("domain", "Xyz");
let _ = json.update_string("username", "MySecret");

let sb = chilkat::StringBuilder::new();
let _ = sb.append("This is the content of the secret.");

// Create or update the secret.
if secrets.update_secret_sb(&json, &sb).is_err() {
    println!("{}", secrets.last_error_text());
    return;
}

println!("Success.");