### List Installed Apps Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Lists all installed applications in the conductor, sorted by installation time. Supports filtering by application status, such as enabled or disabled. ```Rust ListApps { status_filter: Option } ``` -------------------------------- ### Example Minimum Conductor Configuration Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/index Provides an example of a minimum conductor configuration using YAML. This configuration includes settings for the keystore, an admin WebSocket interface, and network parameters like bootstrap and signaling URLs, along with optional WebRTC STUN configuration. It demonstrates how to parse this YAML into a `ConductorConfig` struct using `serde_yaml`. ```yaml --- # Configure the keystore to be used. keystore: # Use an in-process keystore with default database location. type: lair_server_in_proc # Configure an admin WebSocket interface at a specific port. admin_interfaces: - driver: type: websocket port: 1234 allowed_origins: "*" # Configure the network. network: # Use the Holochain-provided dev-test bootstrap server. bootstrap_url: https://dev-test-bootstrap2.holochain.org # Use the Holochain-provided dev-test sbd/signalling server. signal_url: wss://dev-test-bootstrap2.holochain.org # Override the default WebRTC STUN configuration. # This is OPTIONAL. If this is not specified, it will default # to what you can see here: webrtc_config: { "iceServers": [ { "urls": ["stun:devtest-stun-1.holochain.org:443"] } ] } ``` ```rust use holochain_conductor_api::conductor::ConductorConfig; let _: ConductorConfig = serde_yaml::from_str(yaml).unwrap(); ``` -------------------------------- ### Rust Vec shrink_to Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates the `shrink_to` method for Rust Vecs, which shrinks capacity to a specified minimum. The example shows how capacity is adjusted based on the `min_capacity` argument. ```Rust let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3]); assert!(vec.capacity() >= 10); vec.shrink_to(4); assert!(vec.capacity() >= 4); vec.shrink_to(0); assert!(vec.capacity() >= 3); ``` -------------------------------- ### Rust Vec as_slice Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates how to get an immutable slice view of the entire Rust Vec using the `as_slice` method. The example shows writing the vector's contents to a sink. ```Rust use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap(); ``` -------------------------------- ### Rust Vec shrink_to_fit Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Illustrates how to use the `shrink_to_fit` method on a Rust Vec to reduce its capacity to the minimum required. The example shows the capacity before and after shrinking. ```Rust let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3]); assert!(vec.capacity() >= 10); vec.shrink_to_fit(); assert!(vec.capacity() >= 3); ``` -------------------------------- ### Rust Vec into_raw_parts_with_alloc Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates decomposing a `Vec` into its raw pointer, length, capacity, and allocator using `into_raw_parts_with_alloc`. The example shows how to transmute the pointer and reconstruct the Vec. ```Rust #![feature(allocator_api, vec_into_raw_parts)] use std::alloc.System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_raw_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr as *mut u32; Vec::from_raw_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Get Storage Info Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Retrieves information about the storage usage of installed applications within the Holochain conductor. ```rust StorageInfo ``` -------------------------------- ### Rust Vec as_ptr Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Explains how to get a raw pointer to the beginning of the Rust Vec's buffer using `as_ptr`. It highlights the safety considerations and guarantees related to pointer validity and aliasing. ```Rust let v = vec![1, 2, 3]; let ptr = v.as_ptr(); ``` -------------------------------- ### AppInfo from InstalledApp Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/app_interface Constructs an `AppInfo` struct from an `InstalledApp` object. This function extracts details like installed app ID, status, agent public key, manifest, and installation timestamp. It also processes cell information for each role within the app. ```rust impl AppInfo { pub fn from_installed_app( app: &InstalledApp, dna_definitions: &IndexMap, ) -> Self { let installed_app_id = app.id().clone(); let status = app.status().clone().into(); let agent_pub_key = app.agent_key().to_owned(); let mut manifest = app.manifest().clone(); let installed_at = *app.installed_at(); let mut cell_info: IndexMap> = IndexMap::new(); app.roles().iter().for_each(|(role_name, role_assignment)| { // create a vector with info of all cells for this role let mut cell_info_for_role: Vec = Vec::new(); // push the base cell to the vector of cell infos // ... (rest of the implementation) }); Self { installed_app_id, cell_info, status, agent_pub_key, manifest, installed_at, } } } ``` -------------------------------- ### List Apps Response Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Represents the successful response to the AdminRequest::ListApps. It returns a vector of AppInfo, detailing all installed applications within the conductor. ```rust /// The successful response to an [`AdminRequest::ListApps`]. /// /// Contains a list of the `InstalledAppInfo` of the installed apps in the conductor. AppsListed(Vec), ``` -------------------------------- ### Rust Vec from_parts_in with External Allocation Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Illustrates using `Vec::from_parts_in` with memory allocated externally using `Global.allocate`. This example shows how to allocate memory, write data to it, and then construct a Vec from these raw parts. ```Rust #![feature(allocator_api, box_vec_non_null)] use std::alloc::{AllocError, Allocator, Global, Layout}; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let mem = match Global.allocate(layout) { Ok(mem) => mem.cast::(), Err(AllocError) => return, }; mem.write(1_000_000); Vec::from_parts_in(mem, 1, 16, Global) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### Rust Vec as_ptr initialization example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Shows how to initialize a Vec's buffer using `as_ptr` and raw pointer writes before setting the vector's length. ```rust let mut x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } } ``` -------------------------------- ### App Interface: Get App Information Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/app_interface Retrieves information about the connected application, including details of each installed cell. This function is part of the `AppRequest` enum. ```rust /// Get info about the app that you are connected to, including info about each cell installed /// by this app. /// /// # Returns /// /// [`AppResponse::AppInfo`] AppInfo, ``` -------------------------------- ### Rust Path starts_with Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Illustrates the usage of the starts_with method to check if a Path begins with a given prefix. It covers cases with and without trailing slashes. ```Rust use std::path::Path; let path = Path::new("/etc/passwd"); assert!(path.starts_with("/etc")); assert!(path.starts_with("/etc/")); assert!(path.starts_with("/etc/passwd")); assert!(path.starts_with("/etc/passwd/")); // extra slash is okay assert!(path.starts_with("/etc/passwd///")); // multiple extra slashes are okay assert!(!path.starts_with("/e")); assert!(!path.starts_with("/etc/passwd.txt")); assert!(!Path::new("/etc/foo.rs").starts_with("/etc/foo")); ``` -------------------------------- ### Holochain Conductor API - Structs for App Management Source: https://docs.rs/holochain_conductor_api/latest/index This snippet details key structures used for managing Holochain applications and their components. It includes definitions for app authentication, installation details, and cell information. ```Rust pub struct AppInfo { pub installed_app_id: String, pub agent_pubkey: Vec, pub cell_info: std::collections::HashMap, // ... other fields } pub struct ProvisionedCell { pub cell_id: CellId, pub role_name: String, // ... other fields } pub struct IssueAppAuthenticationTokenPayload { pub installed_app_id: String, pub agent_pubkey: Vec, // ... other fields } ``` -------------------------------- ### Rust Vec as_mut_ptr initialization example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Shows how to initialize a Vec's buffer using `as_mut_ptr` and raw pointer writes, followed by setting the vector's length. ```rust // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_mut_ptr(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { *x_ptr.add(i) = i as i32; } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### Holochain Conductor API - Structs for App Management Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/index This snippet details key structures used for managing Holochain applications and their components. It includes definitions for app authentication, installation details, and cell information. ```Rust pub struct AppInfo { pub installed_app_id: String, pub agent_pubkey: Vec, pub cell_info: std::collections::HashMap, // ... other fields } pub struct ProvisionedCell { pub cell_id: CellId, pub role_name: String, // ... other fields } pub struct IssueAppAuthenticationTokenPayload { pub installed_app_id: String, pub agent_pubkey: Vec, // ... other fields } ``` -------------------------------- ### Rust Vec from_parts_in Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates creating a Vec from a NonNull pointer, length, capacity, and allocator. It shows how to manually manage memory and reconstruct the Vec, including overwriting existing data. ```Rust #![feature(allocator_api, box_vec_non_null)] use std::alloc.System; use std::ptr.NonNull; use std::mem; let mut v = Vec::with_capacity_in(3, System); v.push(1); v.push(2); v.push(3); // Prevent running `v`'s destructor so we are in complete control // of the allocation. let mut v = mem::ManuallyDrop::new(v); // Pull out the various important pieces of information about `v` let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) }; let len = v.len(); let cap = v.capacity(); let alloc = v.allocator(); unsafe { // Overwrite memory with 4, 5, 6 for i in 0..len { p.add(i).write(4 + i); } // Put everything back together into a Vec let rebuilt = Vec::from_parts_in(p, len, cap, alloc.clone()); assert_eq!(rebuilt, [4, 5, 6]); } ``` -------------------------------- ### Rust Vec as_non_null initialization example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates initializing a Vec's buffer using `as_non_null` and raw pointer writes, followed by setting the vector's length. Requires the `box_vec_non_null` feature. ```rust #![feature(box_vec_non_null)] // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_non_null(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { x_ptr.add(i).write(i as i32); } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### Rust Path join Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Demonstrates joining a path component to an existing Path to create a new PathBuf. It shows how absolute paths replace the current path. ```Rust use std::path::{Path, PathBuf}; assert_eq!(Path::new("/etc").join("passwd"), PathBuf::from("/etc/passwd")); assert_eq!(Path::new("/etc").join("/bin/sh"), PathBuf::from("/bin/sh")); ``` -------------------------------- ### Enable App Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Enables a specified application within the conductor, allowing its zomes to be called and ensuring it loads on conductor restarts. This is typically called after installing an app. ```Rust EnableApp { installed_app_id: InstalledAppId } ``` -------------------------------- ### Rust Path extension Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Shows how to extract the file extension (without the leading dot) from a Path. It handles single extensions and cases with multiple dots. ```Rust use std::path::Path; assert_eq!("rs", Path::new("foo.rs").extension().unwrap()); assert_eq!("gz", Path::new("foo.tar.gz").extension().unwrap()); ``` -------------------------------- ### Rust Vec as_mut_ptr deallocation example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates manual deallocation of a Vec's backing memory using `Box::from_raw` after wrapping the Vec in `ManuallyDrop` to prevent double-freeing. ```rust use std::mem::{ManuallyDrop, MaybeUninit}; let mut v = ManuallyDrop::new(vec![0, 1, 2]); let ptr = v.as_mut_ptr(); let capacity = v.capacity(); let slice_ptr: *mut [MaybeUninit] = std::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity); drop(unsafe { Box::from_raw(slice_ptr) }); ``` -------------------------------- ### Example Holochain Conductor Configuration Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor Demonstrates a minimal Holochain conductor configuration in YAML format. This includes settings for the keystore, admin WebSocket interface, and network parameters like bootstrap and signal URLs, as well as WebRTC configuration. ```rust #![deny(missing_docs)] //! This module is used to configure the conductor. //! //! #### Example minimum conductor config: //! //! ```rust //! let yaml = r#"--- //! //! ## Configure the keystore to be used. //! keystore: //! //! ## Use an in-process keystore with default database location. //! type: lair_server_in_proc //! //! ## Configure an admin WebSocket interface at a specific port. //! admin_interfaces: //! - driver: //! type: websocket //! port: 1234 //! allowed_origins: "*" //! //! ## Configure the network. //! network: //! //! ## Use the Holochain-provided dev-test bootstrap server. //! bootstrap_url: https://dev-test-bootstrap2.holochain.org //! //! ## Use the Holochain-provided dev-test sbd/signalling server. //! signal_url: wss://dev-test-bootstrap2.holochain.org //! //! ## Override the default WebRTC STUN configuration. //! ## This is OPTIONAL. If this is not specified, it will default //! ## to what you can see here: //! webrtc_config: { //! "iceServers": [ //! { "urls": ["stun:devtest-stun-1.holochain.org:443"] } //! ] //! } //! "#; //! //!use holochain_conductor_api::conductor::ConductorConfig; //! //!let _: ConductorConfig = serde_yaml::from_str(yaml).unwrap(); //! ``` ``` -------------------------------- ### Rust Path file_prefix Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Illustrates extracting the file prefix (name before the first dot) from a Path. It handles cases with leading dots and multiple dots. ```Rust use std::path::Path; assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap()); assert_eq!("foo", Path::new("foo.tar.gz").file_prefix().unwrap()); assert_eq!(".config", Path::new(".config").file_prefix().unwrap()); assert_eq!(".config", Path::new(".config.toml").file_prefix().unwrap()); ``` -------------------------------- ### Get Compatible Cells Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Finds installed cells whose DNA is forward-compatible with a given DNA hash. This is useful for migration scenarios. ```rust #[cfg(feature = "unstable-migration")] GetCompatibleCells(DnaHash) ``` -------------------------------- ### Attach App Interface Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Opens a new websocket interface for processing AppRequests, allowing interaction with installed apps. It supports specifying a port, allowed origins, and optionally binding to a specific app. ```Rust AttachAppInterface { port: Option, allowed_origins: AllowedOrigins, installed_app_id: Option, } ``` -------------------------------- ### Rustdoc Keyboard Shortcuts Source: https://docs.rs/holochain_conductor_api/latest/help Provides a list of keyboard shortcuts for interacting with the Rustdoc documentation interface. These shortcuts allow for efficient navigation, searching, and manipulation of documentation content. ```Rustdoc `?` Show this help dialog `S` / `/` Focus the search field `↑` Move up in search results `↓` Move down in search results `←` / `→` Switch result tab (when results focused) `⏎` Go to active search result `+` Expand all sections `-` Collapse all sections `_` Collapse all sections, including impl blocks ``` -------------------------------- ### Holochain Conductor API Overview Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/lib Provides an overview of the Holochain Conductor API, explaining its role in managing hApps and exposing WebSockets for client connections. It details the split between Admin and App requests and their respective functionalities, including conductor management and direct app interfacing. ```Rust //! Interfaces to manage Holochain applications (hApps) and call their functions. //! //! The Conductor is the central component of Holochain. It exposes WebSockets for clients to //! connect to, processes incoming requests and orchestrates data flow and persistence. //! //! Refer to [Holochain's architecture](https://developer.holochain.org/concepts/2_application_architecture) //! for more info. Read about hApp development in the //! [Happ Development Kit (HDK) documentation](https://docs.rs/hdk/latest/hdk). //! //! There is a [Holochain client for JavaScript](https://github.com/holochain/holochain-client-js) //! and a [Rust client](https://github.com/holochain/holochain-client-rust) //! to connect to the Conductor. //! //! The Conductor API is split into Admin and App requests and responses. Each has //! an associated enum [`AdminRequest`] and [`AppRequest`] that define and //! document available calls. //! //! The admin interface generally manages the conductor itself, such as installing apps, //! listing dnas, cells and apps, accessing state and metric information dumps and managing //! agents. //! //! The app interface is smaller and focussed on interfacing with an app directly. //! Notably the app interface allows calling functions exposed by the hApps's //! modules, called DNAs. To discover a particular hApp's structure, its app //! info can be requested. //! //! Additional information can be found in the [docs module][`crate::docs`]. ``` -------------------------------- ### Create Provisioned CellInfo Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/app_interface Creates a `CellInfo` variant of type `Provisioned`. This constructor takes a `CellId`, `DnaModifiers`, and a `name` string to define a cell that was provisioned during application installation. ```rust impl CellInfo { pub fn new_provisioned(cell_id: CellId, dna_modifiers: DnaModifiers, name: String) -> Self { Self::Provisioned(ProvisionedCell { cell_id, dna_modifiers, name, }) } } ``` -------------------------------- ### Get Parent Path (Rust) Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Shows how to use the `parent` method to get the directory containing the current path. It returns `None` if the path terminates in a root or is empty. ```Rust use std::path::Path; let path = Path::new("/foo/bar"); let parent = path.parent().unwrap(); assert_eq!(parent, Path::new("/foo")); let grand_parent = parent.parent().unwrap(); assert_eq!(grand_parent, Path::new("/")); assert_eq!(grand_parent.parent(), None); let relative_path = Path::new("foo/bar"); let parent = relative_path.parent(); assert_eq!(parent, Some(Path::new("foo"))); let grand_parent = parent.and_then(Path::parent); assert_eq!(grand_parent, Some(Path::new(""))); let great_grand_parent = grand_parent.and_then(Path::parent); assert_eq!(great_grand_parent, None); ``` -------------------------------- ### Create Testing DPKI Configuration Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor/dpki_config Provides a constructor for creating a testing `DpkiConfig`. It uses a testing network seed and enables the option for throwaway random agent keys, suitable for development and CI environments. ```rust #[cfg(feature = "unstable-dpki")] pub fn testing() -> Self { Self { dna_path: None, network_seed: DPKI_NETWORK_SEED_TESTING.to_string(), allow_throwaway_random_dpki_agent_key: true, no_dpki: false, } } ``` -------------------------------- ### Rust Path ends_with Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Shows how to use the ends_with method to determine if a Path terminates with a specific suffix. It includes examples with and without leading slashes for the suffix. ```Rust use std::path::Path; let path = Path::new("/etc/resolv.conf"); assert!(path.ends_with("resolv.conf")); assert!(path.ends_with("etc/resolv.conf")); assert!(path.ends_with("/etc/resolv.conf")); assert!(!path.ends_with("/resolv.conf")); assert!(!path.ends_with("conf")); // use .extension() instead ``` -------------------------------- ### Rust Path: Get Symlink Metadata Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Demonstrates how to get file system metadata without following symbolic links using the `symlink_metadata` method. This is an alias for `fs::symlink_metadata`. ```Rust use std::path::Path; let path = Path::new("/Minas/tirith"); let metadata = path.symlink_metadata().expect("symlink_metadata call failed"); println!("{:?}", metadata.file_type()); ``` -------------------------------- ### Create DataRootPath and Convert to KeystorePath - Rust Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor/paths Defines a `DataRootPath` newtype and implements a conversion to `KeystorePath`. This conversion ensures the keystore directory exists, creating it if necessary, and returns the `KeystorePath`. ```Rust #[derive( shrinkwraprs::Shrinkwrap, derive_more::From, Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, JsonSchema, )] pub struct DataRootPath(PathBuf); impl TryFrom for KeystorePath { type Error = std::io::Error; fn try_from(data_root_path: DataRootPath) -> Result { let path = data_root_path.0.join(KEYSTORE_DIRECTORY); if let Ok(false) = path.try_exists() { std::fs::create_dir_all(path.clone())?; } Ok(Self::from(path)) } } ``` -------------------------------- ### Rust Vec as_mut_slice Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Illustrates obtaining a mutable slice of the entire Rust Vec using `as_mut_slice`. The example shows reading data into the mutable slice from a repeating source. ```Rust use std::io::{self, Read}; let mut buffer = vec![0; 3]; io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap(); ``` -------------------------------- ### Rustdoc Search Tricks Source: https://docs.rs/holochain_conductor_api/latest/help Details advanced search functionalities within Rustdoc, enabling users to refine their searches by item kind, type signature, exact names, and item paths. ```Rustdoc Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given item kind. Accepted kinds are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `-> vec` or `String, enum:Cow -> bool`) You can look for items with an exact name by putting double quotes around your request: `"string"` Look for functions that accept or return slices and arrays by writing square brackets (e.g., `-> [u8]` or `[] -> Option`) Look for items inside another one by searching for a path: `vec::Vec` ``` -------------------------------- ### Create Production DPKI Configuration Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor/dpki_config Provides a constructor for creating a production-ready `DpkiConfig`. It sets the network seed to the main production seed and disables the option for throwaway random agent keys. ```rust #[cfg(feature = "unstable-dpki")] pub fn production(dna_path: Option) -> Self { Self { dna_path, network_seed: DPKI_NETWORK_SEED_MAIN.to_string(), allow_throwaway_random_dpki_agent_key: false, no_dpki: false, } } ``` -------------------------------- ### Rust Vec truncate Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Provides examples of using the `truncate` method on a Rust Vec to shorten it to a specified length. It covers cases where truncation occurs, has no effect, and is equivalent to `clear`. ```Rust let mut vec = vec![1, 2, 3, 4, 5]; vec.truncate(2); assert_eq!(vec, [1, 2]); ``` ```Rust let mut vec = vec![1, 2, 3]; vec.truncate(8); assert_eq!(vec, [1, 2, 3]); ``` ```Rust let mut vec = vec![1, 2, 3]; vec.truncate(0); assert_eq!(vec, []); ``` -------------------------------- ### Conductor Configuration Structs in holochain_conductor_api Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/index Defines various configuration structs for the Holochain conductor, including paths for configuration files, data, keystore, and Wasm modules. These structs are essential for setting up and managing a Holochain conductor instance. ```Rust pub struct ConductorConfig { pub tuning: ConductorTuningParams, pub dpki: DpkiConfig, pub network: NetworkConfig, pub keystore: KeystoreConfig, pub wasm_dir: WasmRootPath, pub config_dir: ConfigRootPath, pub data_dir: DataRootPath, pub databases_dir: DatabasesRootPath, } pub struct ConductorTuningParams {} pub struct DpkiConfig {} pub struct NetworkConfig {} #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum KeystoreConfig { Default, Custom(KeystorePath), } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ConductorConfigError { InvalidPath(String), Io(String), Serde(String), } #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConfigFilePath(pub PathBuf); #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConfigRootPath(pub PathBuf); #[derive(Debug, Clone, PartialEq, Eq)] pub struct DataRootPath(pub PathBuf); #[derive(Debug, Clone, PartialEq, Eq)] pub struct DatabasesRootPath(pub PathBuf); #[derive(Debug, Clone, PartialEq, Eq)] pub struct KeystorePath(pub PathBuf); #[derive(Debug, Clone, PartialEq, Eq)] pub struct WasmRootPath(pub PathBuf); pub type ConductorConfigResult = Result; ``` -------------------------------- ### Rust: Get TypeId Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/storage_info/struct Retrieves the `TypeId` of an object. This method is part of the `Any` trait implementation and is useful for runtime type identification. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Configure Conductor with Lair Server Keystore (Rust & YAML) Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor This Rust and YAML example demonstrates configuring the Holochain conductor to use an external Lair keystore server. It specifies the path to the keystore and provides the connection URL for the Lair server's Unix socket. The test asserts that the configuration correctly sets the `KeystoreConfig` to `LairServer` with the specified connection URL. ```yaml --- data_root_path: /path/to/env keystore_path: /path/to/keystore keystore: type: lair_server connection_url: "unix:///var/run/lair-keystore/socket?k=EcRDnP3xDIZ9Rk_1E-egPE0mGZi5CcszeRxVkb2QXXQ" ``` ```rust let yaml = r###"--- data_root_path: /path/to/env keystore_path: /path/to/keystore keystore: type: lair_server connection_url: "unix:///var/run/lair-keystore/socket?k=EcRDnP3xDIZ9Rk_1E-egPE0mGZi5CcszeRxVkb2QXXQ" "###; let result: ConductorConfigResult = config_from_yaml(yaml); pretty_assertions::assert_eq!( result.unwrap(), ConductorConfig { tracing_override: None, data_root_path: Some(PathBuf::from("/path/to/env").into()), device_seed_lair_tag: None, danger_generate_throwaway_device_seed: false, network: NetworkConfig::default(), dpki: Default::default(), keystore: KeystoreConfig::LairServer { connection_url: url2::url2!("unix:///var/run/lair-keystore/socket?k=EcRDnP3xDIZ9Rk_1E-egPE0mGZi5CcszeRxVkb2QXXQ"), }, ``` -------------------------------- ### Rust: Get TypeId of self Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/storage_info/enum The `type_id` function returns the `TypeId` of the current object, enabling runtime type checking. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get TypeId of a value Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/signal_subscription/enum This method returns the `TypeId` of the current value. It's a fundamental operation for runtime type introspection. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get Type ID Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/enum Retrieves the `TypeId` of a given type. This is a fundamental operation for runtime type introspection and dynamic dispatch. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Rust: Get TypeId for Any Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/enum Retrieves the `TypeId` of a given type. This method is part of the `Any` trait implementation, allowing for runtime type identification. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Holochain Conductor API Structs Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/all Lists the various structs available in the holochain_conductor_api for managing applications, cells, configuration, and state. ```Rust /// Represents a request to authenticate an application. struct AppAuthenticationRequest; /// Represents a token issued for application authentication. struct AppAuthenticationTokenIssued; /// Contains information about an installed application. struct AppInfo; /// Information about an application's interface. struct AppInterfaceInfo; /// Payload for issuing an application authentication token. struct IssueAppAuthenticationTokenPayload; /// Information about a provisioned cell. struct ProvisionedCell; /// Payload for revoking an agent key. struct RevokeAgentKeyPayload; /// Represents a stem cell. struct StemCell; /// Parameters for a signed Zome call. struct ZomeCallParamsSigned; /// Admin interface configuration. mod config::AdminInterfaceConfig; /// Conductor configuration. mod config::conductor::ConductorConfig; /// Conductor tuning parameters. mod config::conductor::ConductorTuningParams; /// DPKI configuration. mod config::conductor::DpkiConfig; /// Network configuration. mod config::conductor::NetworkConfig; /// Configuration file path. mod config::conductor::paths::ConfigFilePath; /// Root path for configuration. mod config::conductor::paths::ConfigRootPath; /// Root path for data. mod config::conductor::paths::DataRootPath; /// Root path for databases. mod config::conductor::paths::DatabasesRootPath; /// Path to the keystore. mod config::conductor::paths::KeystorePath; /// Path to the Wasm directory. mod config::conductor::paths::WasmRootPath; /// Agent meta information. mod peer_meta::AgentMetaInfo; /// Filter for signals. mod signal_subscription::SignalFilter; /// A signal subscription. mod signal_subscription::SignalSubscription; /// Agent information dump. mod state_dump::AgentInfoDump; /// Full integration state dump. mod state_dump::FullIntegrationStateDump; /// Full state dump. mod state_dump::FullStateDump; /// Integration state dump. mod state_dump::IntegrationStateDump; /// Collection of integration state dumps. mod state_dump::IntegrationStateDumps; /// JSON dump of state. mod state_dump::JsonDump; /// Dump of P2P agents. mod state_dump::P2pAgentsDump; /// DNA storage information. mod storage_info::DnaStorageInfo; /// General storage information. mod storage_info::StorageInfo; ``` -------------------------------- ### List Capability Grants Response Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Returns information about capability grants. The response contains AppCapGrantInfo. ```rust /// The successful response to an [`AdminRequest::ListCapabilityGrants`]. CapabilityGrantsInfo(AppCapGrantInfo), ``` -------------------------------- ### Get Websocket Port Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/enum A method to retrieve the port number configured for the Websocket interface driver. This is essential for establishing network connections. ```Rust pub fn port(&self) -> u16 ``` -------------------------------- ### Configure Conductor Interface Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/index This module is used to configure the conductor, specifying how an interface should be opened. ```Rust /// Configuration for interfaces, specifying the means by which an interface should be opened. pub enum InterfaceDriver { // ... variants for different interface configurations } /// Information needed to spawn an admin interface pub struct AdminInterfaceConfig { // ... fields related to admin interface configuration } ``` -------------------------------- ### Rust TypeId Method: Get Type Identifier Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/struct Retrieves the `TypeId` of a given value. This is useful for runtime type identification and comparisons. ```Rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Rust Path with_file_name Example Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/paths/struct Illustrates creating a new PathBuf with a modified file name component, while keeping the rest of the path the same. ```Rust use std::path::{Path, PathBuf}; // Example usage would go here, but the provided text only shows the function signature. ``` -------------------------------- ### Define Conductor Process ERROR_CODE Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/process/constant This constant defines the exit error code for the conductor process if it fails to start. It is an integer value. ```Rust pub const ERROR_CODE: i32 = 42; ``` -------------------------------- ### List DNAs Response Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Represents the successful response to the AdminRequest::ListDnas. It contains a vector of DnaHash, which are the hashes of all installed DNAs in the conductor. ```rust /// The successful response to an [`AdminRequest::ListDnas`]. /// /// Contains a list of the hashes of all installed DNAs. DnasListed(Vec), ``` -------------------------------- ### Rust: CloneToUninit (Nightly) Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/config/conductor/struct An experimental, nightly-only API for cloning data into uninitialized memory. This is an unsafe operation and requires careful handling. ```Rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Rust Vec with Capacity and System Allocator Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Demonstrates creating a `Vec` with a specified capacity using the `System` allocator and adding elements, illustrating reallocation behavior. It also shows creating a `Vec` of a zero-sized type. ```rust #![feature(allocator_api)] use std::alloc::System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### Rust Vec len() - Get Vector Length Source: https://docs.rs/holochain_conductor_api/latest/holochain_conductor_api/type Returns the number of elements currently in the vector (its length). This is a constant time operation. ```Rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### Configure Conductor with Network and Advanced Settings (Rust) Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor This Rust code snippet demonstrates configuring the Holochain conductor with specific network settings, including a signal URL and WebRTC configuration with STUN servers. It also shows how to apply advanced, nested configuration parameters and asserts the resulting configuration against an expected structure. ```rust let network_config = NetworkConfig { signal_url: url2::url2!("wss://test-sig.tld"), webrtc_config: Some(serde_json::json!({ "iceServers": [ { "urls": ["stun:test-stun.tld:443"] }, ] })), advanced: Some(serde_json::json!({ "my": { "totally": { "random": { "advanced": { "config": true, } } } } })), }; pretty_assertions::assert_eq!( result.unwrap(), ConductorConfig { tracing_override: None, data_root_path: Some(PathBuf::from("/path/to/env").into()), device_seed_lair_tag: None, danger_generate_throwaway_device_seed: false, dpki: DpkiConfig::disabled(), keystore: KeystoreConfig::LairServerInProc { lair_root: None }, admin_interfaces: Some(vec![AdminInterfaceConfig { driver: InterfaceDriver::Websocket { port: 1234, allowed_origins: AllowedOrigins::Any } }]), network: network_config, db_sync_strategy: DbSyncStrategy::Fast, #[cfg(feature = "chc")] chc_url: None, tuning_params: None, tracing_scope: None, } ); ``` -------------------------------- ### Get Conductor Tuning Parameters Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/config/conductor Retrieves the conductor tuning parameters. If the `tuning_params` field is not set in the configuration, it returns the default `ConductorTuningParams`. ```Rust impl ConductorConfig { /// Get the conductor tuning params for this config (default if not set) pub fn conductor_tuning_params(&self) -> ConductorTuningParams { self.tuning_params.clone().unwrap_or_default() } } ``` -------------------------------- ### Get Compatible Cells Response Source: https://docs.rs/holochain_conductor_api/latest/src/holochain_conductor_api/admin_interface Provides a set of compatible cells for migration purposes. This response is conditional on the 'unstable-migration' feature being enabled. ```rust /// The successful response to an [`AdminRequest::GetCompatibleCells`]. /// /// #[cfg(feature = "unstable-migration")] /// CompatibleCells(CompatibleCells), ```