You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use atomic_lib::{agents::Agent, errors::AtomicResult,Resource,Store,Storelike};use std::env;/// Creates a new Class resource in an Atomic Data store./// Requires two environment variables:/// - ATOMIC_SERVER_URL: The base URL of the Atomic Server (e.g., "https://atomicdata.dev")/// - ATOMIC_AGENT_SECRET: The private key of the Agent that will create the Class////// # Returns/// - `AtomicResult<String>`: The subject URL of the newly created Class////// # Example usage:/// ```bash/// export ATOMIC_SERVER_URL="https://localhost:9883"/// export ATOMIC_AGENT_SECRET="secret_key_here"/// cargo run/// ```fnmain() -> AtomicResult<()>{// Initialize store with server URL from environmentlet server_url = env::var("ATOMIC_SERVER_URL").map_err(|_| "ATOMIC_SERVER_URL environment variable not set")?;letmut store = Store::init()?;println!("Server URL: {}", store.get_server_url());// Initialize agent from secretlet agent_secret = env::var("ATOMIC_AGENT_SECRET").map_err(|_| "ATOMIC_AGENT_SECRET environment variable not set")?;let agent = Agent::from_secret(&agent_secret)?;
store.set_default_agent(agent);// Create a new Class instanceletmut class_resource =
Resource::new_instance("https://atomicdata.dev/classes/Class",&store)?;// Set required properties for the Class
class_resource
// shortname is required for all Classes.set_shortname("shortname","person",&store)?
// description is required for all Classes.set_shortname("description","Represents a human being with various properties",&store,)?;// Save the resource to the server// This will create a Commit and send it to the server
class_resource.save(&store)?;let subject = class_resource.get_subject();println!("Successfully created new Class!");println!("Subject URL: {}", subject);Ok(())}
I can create a store object in Javascript and pass the Atomic Server URL and Agent (secret).
I can't figure out how to do it in Rust.
The text was updated successfully, but these errors were encountered:
I have tried to build a new example:
I can create a store object in Javascript and pass the Atomic Server URL and Agent (secret).
I can't figure out how to do it in Rust.
The text was updated successfully, but these errors were encountered: