### get() example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Returns a reference to an element or subslice depending on the type of index. The example shows getting an element by position, a subslice by range, and out-of-bounds cases returning None. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### MCPServer::start_direct method Source: https://docs.rs/rustcodegraph/latest/src/rustcodegraph/mcp/index.rs.html?search= Starts the server in direct mode, setting up the engine, stdin guard, liveness watchdog, and transport. Returns a StartOutcome::Direct with the given reason. ```rust fn start_direct(&mut self, reason: &str) -> StartOutcome { self.mode = MCPServerMode::Direct; self.engine = Some(MCPEngine::new(None)); self.stdin_guard = Some(treat_stdin_failure_as_shutdown(|| {})); self.liveness_watchdog = install_main_thread_watchdog(); let _transport = StdioTransport::default(); StartOutcome::Direct { reason: reason.to_string(), } } ``` -------------------------------- ### Vec::push_mut example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Example of using Vec::push_mut to append an element and get a mutable reference to it. ```rust let mut vec = vec![1, 2]; let last = vec.push_mut(3); assert_eq!(*last, 3); assert_eq!(vec, [1, 2, 3]); let last = vec.push_mut(3); *last += 1; assert_eq!(vec, [1, 2, 3, 4]); ``` -------------------------------- ### initialize Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/index/struct.DatabaseConnection.html?search=std%3A%3Avec Initializes a new database at the given path. ```APIDOC ## initialize(db_path: impl AsRef) -> SqliteResult ### Description Initializes a new database at the given path. Creates parent directories, executes the full schema, and writes the current schema version. Does not run historical migrations for new databases. ### Method initialize ### Parameters - **db_path** (impl AsRef) - Required - Path to the database file. ### Returns - **SqliteResult** - Result containing the new DatabaseConnection or an error. ``` -------------------------------- ### len example: get number of elements Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Shows how to get the length of a vector using len, with an assertion verifying the result. ```rust let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### pub fn initialize(db_path: impl AsRef) -> SqliteResult Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/index/struct.DatabaseConnection.html Initializes a new database at the given path, creating parent directories and applying the full schema. ```APIDOC ## pub fn initialize(db_path: impl AsRef) -> SqliteResult ### Description Initializes a new database at the given path. Creates parent directories, executes the full schema, and writes the current schema version. For new databases, it does not run historical migrations; the schema.sql represents the latest structure, and the version record is used by subsequent `open` calls to determine if incremental migration is needed. ### Parameters - **db_path** (impl AsRef) - Required - The path where the database file should be created. ### Returns - **SqliteResult** - A result containing the initialized DatabaseConnection or an error. ``` -------------------------------- ### get method example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/sqlite_adapter/type.SqliteRow.html?search= Returns a reference to the value corresponding to the key. The example inserts a key-value pair and retrieves it, also checking for a missing key. ```rust use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None); ``` -------------------------------- ### DatabaseConnection::initialize Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/index/struct.DatabaseConnection.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new database at the given path, creating parent directories and applying the full schema. ```APIDOC ## DatabaseConnection::initialize ### Description Initializes a new database at the given path. Creates parent directories, executes the full schema, and writes the current schema version. ### Method initialize ### Signature pub fn initialize(db_path: impl AsRef) -> SqliteResult ### Parameters - **db_path** (impl AsRef) - Required - Path to the database file. ### Returns - **SqliteResult** - Result containing the new DatabaseConnection or an error. ``` -------------------------------- ### entry method example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/sqlite_adapter/type.SqliteRow.html?search= Gets the given key's corresponding entry in the map for in-place manipulation. The example counts character frequencies in a string using entry and and_modify/or_insert. ```rust use std::collections::HashMap; let mut letters = HashMap::new(); for ch in "a short treatise on fungi".chars() { letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1); } assert_eq!(letters[&'s'], 2); assert_eq!(letters[&'t'], 3); assert_eq!(letters[&'u'], 1); assert_eq!(letters.get(&'y'), None); ``` -------------------------------- ### MCPServer::new Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/index/struct.MCPServer.html Creates a new MCPServer instance with an optional project path. ```APIDOC ## MCPServer::new ### Description Creates a new MCPServer instance with an optional project path. ### Method new ### Signature pub fn new(project_path: Option) -> Self ### Parameters - **project_path** (Option) - Optional - The path to the project. ### Returns - **Self** - A new MCPServer instance. ``` -------------------------------- ### pub fn client_hello(host_ppid_env: Option<&str>, current_ppid: u32) -> DaemonClientHello Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/proxy/fn.client_hello.html Constructs a `DaemonClientHello` message for the MCP proxy. Takes an optional host process ID environment variable and the current process ID, returning the hello message. ```APIDOC ## Function: client_hello ### Description Constructs a `DaemonClientHello` message for the MCP proxy. ### Signature ```rust pub fn client_hello( host_ppid_env: Option<&str>, current_ppid: u32, ) -> DaemonClientHello ``` ### Parameters - **host_ppid_env** (`Option<&str>`) - Optional host process ID environment variable. - **current_ppid** (`u32`) - Current process ID. ### Returns - **DaemonClientHello** - The constructed hello message. ``` -------------------------------- ### Box::into_inner example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/sync/watcher/type.SyncErrorCallback.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates using Box::into_inner to consume a Box and return the wrapped value. The example creates a Box containing 5 and then uses into_inner to get the value. ```rust #![feature(box_into_inner)] let c = Box::new(5); ``` -------------------------------- ### rsplit example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Returns an iterator over subslices separated by matching elements, starting from the end. The example shows a basic case and a case where the first element matches, producing an empty slice first. ```rust let slice = [11, 22, 33, 0, 44, 55]; let mut iter = slice.rsplit(|num| *num == 0); assert_eq!(iter.next().unwrap(), &[44, 55]); assert_eq!(iter.next().unwrap(), &[11, 22, 33]); assert_eq!(iter.next(), None); ``` ```rust let v = &[0, 1, 1, 2, 3, 5, 8]; let mut it = v.rsplit(|n| *n % 2 == 0); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next().unwrap(), &[3, 5]); assert_eq!(it.next().unwrap(), &[1, 1]); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next(), None); ``` -------------------------------- ### DatabaseConnection::initialize Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/index/struct.DatabaseConnection.html?search=u32+-%3E+bool Initializes a new database at the given path, creating parent directories, executing the full schema, and writing the current schema version. ```APIDOC ## initialize ### Description Initializes a new database at the given path. Creates parent directories, executes the full schema, and writes the current schema version. Does not run historical migrations for new databases. ### Method initialize ### Signature pub fn initialize(db_path: impl AsRef) -> SqliteResult ### Parameters - **db_path** (impl AsRef) - Required - Path to the database file. ### Returns - **SqliteResult** - Result containing the initialized DatabaseConnection or an error. ``` -------------------------------- ### Daemon::start Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/daemon/struct.Daemon.html?search= Starts the daemon. Runtime socket binding is intentionally deferred for this translation. ```APIDOC ## Daemon::start ### Description Starts the daemon. Runtime socket binding is intentionally deferred for this translation. ### Method `pub fn start(&mut self) -> Result` ### Parameters - **self** (&mut self) - Required - Mutable reference to the daemon. ### Returns - **Result** - The result of starting the daemon. ``` -------------------------------- ### Arc::strong_count example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/resolution/frameworks/index/type.ResolverRef.html?search=std%3A%3Avec Gets the number of strong (Arc) pointers to the allocation. Safe to call, but another thread can change the count at any time. The example asserts the count is 2 after cloning the Arc. ```rust use std::sync::Arc; let five = Arc::new(5); let _also_five = Arc::clone(&five); // This assertion is deterministic because we haven't shared // the `Arc` between threads. assert_eq!(2, Arc::strong_count(&five)); ``` -------------------------------- ### Arc::weak_count example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/resolution/frameworks/index/type.ResolverRef.html?search=std%3A%3Avec Gets the number of Weak pointers to the allocation. Safe to call, but another thread can change the count at any time. The example asserts the count is 1 because the Arc and Weak are not shared between threads. ```rust use std::sync::Arc; let five = Arc::new(5); let _weak_five = Arc::downgrade(&five); // This assertion is deterministic because we haven't shared // the `Arc` or `Weak` between threads. assert_eq!(1, Arc::weak_count(&five)); ``` -------------------------------- ### pub fn client_hello_line(host_ppid_env: Option<&str>, current_ppid: u32) -> String Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/proxy/fn.client_hello_line.html?search=std%3A%3Avec Constructs a client hello line for the MCP proxy. It takes an optional host process ID environment variable and the current process ID, and returns a formatted string. ```APIDOC ## Function: client_hello_line ### Description Constructs a client hello line for the MCP proxy. It takes an optional host process ID environment variable and the current process ID, and returns a formatted string. ### Signature ```rust pub fn client_hello_line( host_ppid_env: Option<&str>, current_ppid: u32, ) -> String ``` ### Parameters - **host_ppid_env** (`Option<&str>`) - Optional host process ID environment variable. - **current_ppid** (`u32`) - Current process ID. ### Return Value - **String** - The constructed client hello line. ### Source Code ```rust pub fn client_hello_line( host_ppid_env: Option<&str>, current_ppid: u32, ) -> String ``` ``` -------------------------------- ### Get nodes by file Source: https://docs.rs/rustcodegraph/latest/src/rustcodegraph/db/queries/nodes.rs.html?search=std%3A%3Avec Retrieves all nodes associated with a specific file path, ordered by start line. ```rust /// Get all nodes in a file. pub fn get_nodes_by_file(&mut self, file_path: &str) -> SqliteResult> { let stmt = Self::prepare_cached( self.db, &mut self.stmts.get_nodes_by_file, "SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line", )?; map_rows(stmt.all(positional(vec![file_path]))?, row_to_node) } ``` -------------------------------- ### start Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/sync/watcher/struct.FileWatcher.html Starts the file watcher, selecting a recursive or per-directory strategy based on the platform. ```APIDOC ## start ### Description Starts the file watcher, selecting a recursive or per-directory strategy based on the platform. ### Method start ### Signature ```rust pub fn start(&mut self) -> bool ``` ### Parameters None ### Returns - **bool** - Whether the watcher started successfully. ``` -------------------------------- ### Get all nodes in a file Source: https://docs.rs/rustcodegraph/latest/src/rustcodegraph/db/queries/nodes.rs.html Fetches all nodes associated with a given file path, ordered by start line. ```rust let stmt = Self::prepare_cached( self.db, &mut self.stmts.get_nodes_by_file, "SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line", )?; map_rows(stmt.all(positional(vec![file_path]))?, row_to_node) ``` -------------------------------- ### pub fn new(opts: Option) -> Self Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/engine/struct.MCPEngine.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new MCPEngine instance with optional configuration options. ```APIDOC ## pub fn new(opts: Option) -> Self ### Description Constructs a new MCPEngine with the provided options. If `None` is passed, default options are used. ### Parameters - **opts** (Option) - Optional configuration for the engine. ### Returns - **Self** - A new MCPEngine instance. ### Example ```rust let engine = MCPEngine::new(None); ``` ``` -------------------------------- ### new Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/context/index/struct.ContextBuilder.html?search= Creates a new ContextBuilder instance with the given project root and query builder. This is the constructor for the builder. ```APIDOC ## new ### Description Creates a new ContextBuilder instance with the given project root and query builder. This is the constructor for the builder. ### Method Rust constructor ### Signature ```rust pub fn new( project_root: impl Into, queries: &'a mut QueryBuilder<'db>, ) -> Self ``` ### Parameters - **project_root** (`impl Into`) - Required - The root path of the project. - **queries** (`&'a mut QueryBuilder<'db>`) - Required - A mutable reference to a query builder. ### Returns - **Self** - A new instance of ContextBuilder. ``` -------------------------------- ### Get nodes by file Source: https://docs.rs/rustcodegraph/latest/src/rustcodegraph/db/queries/nodes.rs.html?search=u32+-%3E+bool Retrieves all nodes in a file, ordered by start line. Used in the get_nodes_by_file method. ```sql SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line ``` -------------------------------- ### MCPSession::start Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/session/struct.MCPSession.html Starts the MCP session. ```APIDOC ## MCPSession::start ### Description Starts the MCP session, initializing the underlying transport and engine. ### Method start ### Signature ```rust pub fn start(&mut self) ``` ### Parameters None. ### Returns - **()** - Unit type. ``` -------------------------------- ### strip_prefix example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Demonstrates the strip_prefix method on a slice. It returns Some with the subslice after the prefix if the slice starts with the prefix, otherwise None. The example shows various cases including empty prefix and prefix equal to the whole slice. ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` -------------------------------- ### MCPServer::start Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/index/struct.MCPServer.html Starts the MCP server and returns the runtime mode without starting processes or sockets. ```APIDOC ## MCPServer::start ### Description Starts the MCP server and returns the runtime mode without starting processes or sockets. ### Method start ### Signature pub fn start(&mut self) -> StartOutcome ### Parameters - **self** (&mut self) - Required - The mutable reference to the MCPServer instance. ### Returns - **StartOutcome** - The outcome of the start operation, indicating the runtime mode. ``` -------------------------------- ### get_disjoint_unchecked_mut example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/sqlite_adapter/type.SqliteRow.html?search= Uses unsafe code to get mutable references to multiple keys at once. Missing keys result in None. ```rust // SAFETY: The keys do not overlap. let got = unsafe { libraries.get_disjoint_unchecked_mut([ "Athenæum", "New York Public Library", ]) }; // Missing keys result in None assert_eq!(got, [Some(&mut 1807), None]); ``` -------------------------------- ### as_rchunks example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Splits the slice into N-element arrays starting from the end, with a remainder of length less than N. Panics if N is zero. ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let (remainder, chunks) = slice.as_rchunks(); assert_eq!(remainder, &['l']); assert_eq!(chunks, &[['o', 'r'], ['e', 'm']]); ``` -------------------------------- ### MCPSession::start Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/session/struct.MCPSession.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts the MCP session, initializing the underlying transport and preparing it for handling requests. ```APIDOC ## MCPSession::start ### Description Starts the MCP session, initializing the underlying transport and preparing it for handling requests. ### Method Instance Method ### Signature ```rust pub fn start(&mut self) ``` ### Parameters None ### Returns - **()** - Unit type, indicating successful start. ``` -------------------------------- ### MCPSession::handle_initialize Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/session/struct.MCPSession.html Handles an initialize request. ```APIDOC ## MCPSession::handle_initialize ### Description Handles an initialize request from the client. ### Method handle_initialize ### Signature ```rust pub fn handle_initialize(&mut self, request: &JsonRpcRequest) ``` ### Parameters - **request** (&JsonRpcRequest) - Required - The JSON-RPC request to handle. ### Returns - **()** - Unit type. ``` -------------------------------- ### as_mut example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/db/sqlite_adapter/type.SqliteResult.html?search= Shows using as_mut to get a mutable reference to the contained value, allowing mutation of the Ok or Err variant. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### rsplitn example: split slice from end by predicate Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/web_tree_sitter/struct.NodeList.html?search=std%3A%3Avec Splits the slice into at most n subslices starting from the end, separated by elements matching the predicate. The matched element is not included. This example prints the two groups after splitting once from the end by numbers divisible by 3. ```rust let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{group:?}"); } ``` -------------------------------- ### new Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/tools/struct.ToolHandler.html?search=std%3A%3Avec Creates a new ToolHandler instance with a default project loaded flag. ```APIDOC ## pub fn new(default_project_loaded: bool) -> Self ### Description Creates a new `ToolHandler` instance. ### Parameters - `default_project_loaded`: bool - Indicates whether a default project is loaded. ### Returns - `Self` - The new `ToolHandler`. ``` -------------------------------- ### MCPEngine::new Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/engine/struct.MCPEngine.html?search=std%3A%3Avec Creates a new MCPEngine instance with optional configuration options. ```APIDOC ## MCPEngine::new ### Description Creates a new MCPEngine instance with optional configuration options. ### Method `pub fn new(opts: Option) -> Self` ### Parameters - `opts` (Option) - Optional configuration options for the engine. ### Returns - `Self` - A new MCPEngine instance. ``` -------------------------------- ### Get string slice with as_str Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/mcp/transport/type.JsonRpcIdKey.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Extracts a string slice containing the entire String. The example shows that the slice equals the original string. ```rust let s = String::from("foo"); assert_eq!("foo", s.as_str()); ``` -------------------------------- ### initialize_local_project_plan Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/installer/index/fn.initialize_local_project_plan.html Initializes a local project plan. It accepts a location and a flag indicating whether to use defaults, returning an optional string result. ```APIDOC ## Function: initialize_local_project_plan ### Description Initializes a local project plan. It accepts a location and a flag indicating whether to use defaults, returning an optional string result. ### Signature ```rust pub fn initialize_local_project_plan( loc: Location, use_defaults: bool, ) -> Option ``` ### Parameters - **loc** (Location) - Required - The location for the project plan. - **use_defaults** (bool) - Required - Whether to use default settings. ### Returns - **Option** - An optional string result, possibly containing a plan or error message. ``` -------------------------------- ### Arc::try_unwrap example Source: https://docs.rs/rustcodegraph/latest/rustcodegraph/resolution/frameworks/index/type.ResolverRef.html?search=std%3A%3Avec Shows how to use Arc::try_unwrap to get the inner value when there is exactly one strong reference. The example asserts Ok(3) when unwrapping a single Arc, and demonstrates that with a clone, try_unwrap returns an Err containing the original Arc. ```rust use std::sync::Arc; let x = Arc::new(3); assert_eq!(Arc::try_unwrap(x), Ok(3)); let x = Arc::new(4); let _y = Arc::clone(&x); assert_eq!(*Arc::try_unwrap(x).unwrap_err(), 4); ```