### Example: Using #[launch] for Rocket Application (Rust) Source: https://docs.rs/rocket/latest/rocket/fn.execute_search=u32+-%3E+bool Provides an example of how to use the `#[rocket::launch]` attribute to start a Rocket application. This attribute simplifies the process of setting up the asynchronous runtime and launching the server, even when Rocket is part of a larger application. ```rust #[rocket::launch] async fn rocket() -> Rocket { rocket::build() } ``` -------------------------------- ### Get length of Vec in Rust (Example) Source: https://docs.rs/rocket/latest/rocket/mtls/oid/asn1_rs/nom/trait.Parser_search=std%3A%3Avec A conceptual example demonstrating how to get the number of elements in a vector. ```rust let my_vec = vec![1, 2, 3, 4, 5]; let length = my_vec.len(); // length will be 5 ``` -------------------------------- ### Rocket FileServer: Basic Options Initialization Source: https://docs.rs/rocket/latest/rocket/fs/struct.Options_search=std%3A%3Avec Demonstrates the initialization of a FileServer with specific options. This example shows how to enable both index file serving and dot file access by combining `Options::Index` and `Options::DotFiles`. ```rust use rocket::fs::FileServer; #[launch] fn rocket() -> _ { rocket::build() .mount("/files", FileServer::new("static").with_options(rocket::fs::Options::Index | rocket::fs::Options::DotFiles)) } ``` -------------------------------- ### Construct FileServer with Path and Options Source: https://docs.rs/rocket/latest/rocket/fs/struct.FileServer This example demonstrates constructing a FileServer using `FileServer::new()` with specific options (Index and DotFiles) and a custom rank. ```Rust use rocket::fs::{FileServer, Options}; #[launch] fn rocket() -> _ { let options = Options::Index | Options::DotFiles; rocket::build() .mount("/static", FileServer::from("/www/public")) .mount("/pub", FileServer::new("/www/public", options).rank(-1)) } ``` -------------------------------- ### Rocket Basic Get Route Example Source: https://docs.rs/rocket/latest/rocket/attr.delete_search= A fundamental example of a Rocket `GET` route. It demonstrates a simple free function decorated with `#[get("/")]` that returns a static string, illustrating the basic structure for defining a web endpoint. ```Rust #[get("/")] fn index() -> &'static str { "Hello, world!" } ``` -------------------------------- ### Get mutable remaining slice of Vec in Rust (Example) Source: https://docs.rs/rocket/latest/rocket/mtls/oid/asn1_rs/nom/trait.Parser_search=std%3A%3Avec A conceptual example demonstrating how to get a mutable slice representing the remaining uninitialized portion of a byte vector. ```rust let mut buffer: Vec = vec![0; 1024]; let initialized_len = 512; let remaining = &mut buffer[initialized_len..]; let mutable_slice = rocket::mtls::oid::asn1_rs::nom::lib::std::vec::Vec::remaining_mut(&mut buffer); ``` -------------------------------- ### Rocket Configuration Example Source: https://docs.rs/rocket/latest/rocket/struct.Rocket_search=std%3A%3Avec Demonstrates how to create and configure a Rocket instance using a custom configuration, including setting the port, address, and temporary directory. It also shows how to modify the configuration using Figment. ```APIDOC ## Rocket Configuration Example ### Description This example illustrates setting up a custom Rocket configuration with specific port, address, and temporary directory settings. It also demonstrates updating these configurations dynamically using Rocket's Figment API. ### Method N/A (Configuration Setup) ### Endpoint N/A (Configuration Setup) ### Parameters N/A ### Request Example ```rust use rocket::Config; use std::net::Ipv4Addr; use std::path::Path; let config = Config { port: 7777, address: Ipv4Addr::new(18, 127, 0, 1).into(), temp_dir: "/tmp/config-example".into(), ..Config::debug_default() }; // ... Rocket ignition and assertion ... let figment = rocket.figment().clone() .merge((Config::PORT, 8888)) .merge((Config::ADDRESS, "171.64.200.10")); let rocket = rocket::custom(&config) .configure(figment) .ignite().await?; // ... assertions ... ``` ### Response N/A (Configuration Setup) ``` -------------------------------- ### Get Start Bound of a Range (Rust) Source: https://docs.rs/rocket/latest/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/struct.Range Returns the start bound of a `Range` for types implementing `RangeBounds`. This is applicable to `Range<&T>`. ```rust fn start_bound(&self) -> Bound<&T> ``` -------------------------------- ### Example Usage Source: https://docs.rs/rocket/latest/rocket/local/asynchronous/struct.Client Example of creating a Client from a Rocket instance and dispatching a local POST request. ```APIDOC ### Example The following snippet creates a `Client` from a `Rocket` instance and dispatches a local `POST /` request with a body of `Hello, world!`. ```rust use rocket::local::asynchronous::Client; let rocket = rocket::build(); let client = Client::tracked(rocket).await.expect("valid rocket"); let response = client.post("/") .body("Hello, world!") .dispatch() .await; ``` ``` -------------------------------- ### Rust: Get Start and End Bounds of RangeInclusive Source: https://docs.rs/rocket/latest/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/struct.RangeInclusive_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to retrieve the start and end bounds of a `RangeInclusive` using the `start()` and `end()` methods. It also notes that these values are unspecified after iteration. ```Rust assert_eq!((3..=5).start(), &3); ``` ```Rust assert_eq!((3..=5).end(), &5); ``` -------------------------------- ### Initialize FileServer with Options (Rust) Source: https://docs.rs/rocket/latest/src/rocket/fs/server.rs_search=u32+-%3E+bool Demonstrates initializing FileServer with specific options to control its behavior, such as disabling index file serving or dot file serving. This example shows serving files with custom options and different ranks. ```rust # #[macro_use] extern crate rocket; use rocket::fs::FileServer; #[launch] fn rocket() -> _ { // Example usage is missing in the provided text, this is a placeholder rocket::build() } ``` -------------------------------- ### Getting Content-Type from LocalResponse Source: https://docs.rs/rocket/latest/rocket/local/asynchronous/struct.LocalResponse_search= This example demonstrates how to get the `ContentType` from a `LocalResponse`. It returns an `Option` because the content type might not be set or might be invalid. ```rust use rocket::local::asynchronous::LocalResponse; let response: LocalResponse = response; let content_type = response.content_type(); ``` -------------------------------- ### Route::new Example Source: https://docs.rs/rocket/latest/rocket/route/struct.Route_search=std%3A%3Avec An example demonstrating the usage of the `Route::new` constructor. ```APIDOC ## Route::new ### Description Creates a new `Route` with a default rank. This is a convenient constructor for common routing scenarios. ### Method Associated Function (`Route::new`) ### Endpoint N/A (Constructor) ### Parameters - **method** (`Method`): The HTTP method for the route. - **uri** (`&str`): The URI path for the route. Must be a valid Rocket route URI. - **handler** (`H` where `H: Handler`): The handler function for this route. ### Panics Panics if `uri` is not a valid Rocket route URI. ### Example ```rust use rocket::Route; use rocket::http::Method; // This is a rank -9 route matching requests to `GET /` let index = Route::new(Method::Get, "/", rocket::route::dummy_handler); assert_eq!(index.rank, -9); assert_eq!(index.method, Method::Get); assert_eq!(index.uri, "/"); ``` ``` -------------------------------- ### Initialization and Styling Methods Source: https://docs.rs/rocket/latest/rocket/mtls/x509/struct.ASN1Time_search=u32+-%3E+bool Methods for creating new `Painted` instances and applying wholesale styles. ```APIDOC ## Initialization and Styling ### new Create a new `Painted` with a default `Style`. #### Method `new(self) -> Painted` #### Constraints `where Self: Sized` ### paint Apply a style wholesale to `self`. Any previous style is replaced. #### Method `paint(&self, style: S) -> Painted<&Self>` #### Constraints `where S: Into