### mdns-proto Installation with no_std and alloc Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Use this configuration for no_std environments with an allocator. ```toml mdns-proto = { version = "0.3", default-features = false, features = ["alloc"] } ``` -------------------------------- ### Install Metrics Recorder Source: https://github.com/al8n/hick/blob/main/README.md Install a metrics recorder before starting the endpoint when the 'metrics' feature is enabled. This example uses the prometheus exporter. ```rust // Example using the prometheus exporter from the `metrics-exporter-prometheus` crate: metrics_exporter_prometheus::PrometheusBuilder::new().install().unwrap(); ``` -------------------------------- ### Run hick-compio Example Source: https://github.com/al8n/hick/blob/main/hick-compio/README.md This example demonstrates how to run hick-compio within a compio runtime. It shows how to advertise a service and discover other services. ```rust use hick_compio::{ Endpoint, Name, QueryEvent, QuerySpec, ServerOptions, ServiceRecords, ServiceSpec, wire::ResourceType, }; async fn run() -> Result<(), Box> { let endpoint = Endpoint::server(ServerOptions::default()).await?; // Advertise a service. Keep the handle alive to keep advertising; dropping it // withdraws the service (TTL=0 goodbye) and unregisters it. let mut records = ServiceRecords::new( Name::try_from_str("_http._tcp.local.")?, Name::try_from_str("My Device._http._tcp.local.")?, Name::try_from_str("my-device.local.")?, 80, 120, ); records.add_a([192, 168, 1, 10].into()); let _service = endpoint.register_service(ServiceSpec::new(records)).await?; // Discover services of a type on the local link. let mut query = endpoint .start_query(QuerySpec::new( Name::try_from_str("_ipp._tcp.local.")?, ResourceType::Ptr, )) .await?; while let Some(event) = query.next().await { match event { QueryEvent::Answer(answer) => println!(ירת{answer:?})?, QueryEvent::Terminal(_) => break, } } Ok(()) } ``` -------------------------------- ### mdns-proto Installation with std Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Add this to your Cargo.toml for standard library support. ```toml [dependencies] mdns-proto = "0.3" # std + slab ``` -------------------------------- ### mdns-proto Installation with bare no_std Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Use this for bare no_std environments without an allocator. ```toml mdns-proto = { version = "0.3", default-features = false } ``` -------------------------------- ### Run mDNS Server and Discover Services (Tokio) Source: https://github.com/al8n/hick/blob/main/hick-reactor/README.md This example demonstrates how to set up an mDNS server, advertise a service, and discover other services on the local network using the tokio runtime. Ensure the service handle is kept alive to maintain advertisement. Dropping the handle withdraws the service. ```rust use hick_reactor::{ Name, QuerySpec, ServerOptions, ServiceRecords, ServiceSpec, tokio, wire::ResourceType, }; async fn run() -> Result<(), Box> { // `tokio::server` / `smol::server` pin the runtime; the returned `Endpoint` // and its handles are otherwise the same. let endpoint = tokio::server(ServerOptions::default()).await?; // Advertise a service. Keep the handle alive to keep advertising; dropping it // withdraws the service (TTL=0 goodbye) and unregisters it. let mut records = ServiceRecords::new( Name::try_from_str("_http._tcp.local.")?, Name::try_from_str("My Device._http._tcp.local.")?, Name::try_from_str("my-device.local.")?, 80, 120, ); records.add_a([192, 168, 1, 10].into()); let _service = endpoint.register_service(ServiceSpec::new(records)).await?; // Discover services of a type on the local link. let mut query = endpoint .start_query(QuerySpec::new( Name::try_from_str("_ipp._tcp.local.")?, ResourceType::Ptr, )) .await?; while let Some(event) = query.next().await { match event { hick_reactor::QueryEvent::Answer(answer) => println!(ירת{answer:?}), hick_reactor::QueryEvent::Terminal(_) => break, } } Ok(()) } ``` -------------------------------- ### Hick Installation with Compio Runtime Source: https://github.com/al8n/hick/blob/main/README.md Configure 'hick' to use the 'compio' runtime by disabling default features and enabling the 'compio' feature. ```toml [dependencies] hick = { version = "0.1", default-features = false, features = ["compio"] } ``` -------------------------------- ### mdns-proto Installation with no_std, alloc, and no native atomics Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Required for no_std environments with alloc on cores lacking native atomics, such as Cortex-M0+ or RP2040. ```toml mdns-proto = { version = "0.3", default-features = false, features = ["no-atomic"] } ``` -------------------------------- ### Hick Installation with Smol Runtime Source: https://github.com/al8n/hick/blob/main/README.md Configure 'hick' to use the 'smol' runtime by disabling default features and enabling the 'smol' feature. ```toml [dependencies] hick = { version = "0.1", default-features = false, features = ["smol"] } ``` -------------------------------- ### Default Hick Installation Source: https://github.com/al8n/hick/blob/main/README.md Add the 'hick' crate to your dependencies for the default tokio runtime configuration. ```toml [dependencies] hick = "0.1" # tokio runtime by default ``` -------------------------------- ### Initialize and Register Service with hick-smoltcp Engine Source: https://github.com/al8n/hick/blob/main/hick-smoltcp/README.md This example shows how to initialize the hick-smoltcp engine and register a service. The engine manages protocol state using slab-backed pools for efficiency. Ensure you have a random number generator and current time available. ```rust use hick_smoltcp::{DualStack, Engine}; use mdns_proto::{EndpointConfig, Name, ServiceRecords, ServiceSpec}; // The engine wires mdns-proto's alloc-tier state machines to any `UdpIo`. For // smoltcp, use the family-aware `DualStack` over your v4 and/or v6 socket handles. let mut engine = Engine::new(EndpointConfig::new(), rng); let mut records = ServiceRecords::new( Name::try_from_str("_http._tcp.local.")?, Name::try_from_str("My Device._http._tcp.local.")?, Name::try_from_str("mydevice.local.")?, 80, 120, ); records.add_a(my_ipv4); engine.register_service(ServiceSpec::new(records), now)?; // Pump from your own loop, handing it a `DualStack` view of your sockets and a // scratch buffer. The engine fans each multicast to BOTH groups, so `DualStack` // routes by family (leave a family `None` for a single-stack node). `pump` returns // the next instant the engine wants to be polled. loop { let mut io = DualStack::new(&mut sockets, Some(v4_handle), Some(v6_handle)); let next = engine.pump(now, &mut io, &mut scratch); // ...advance the smoltcp interface (iface.poll(.., &mut sockets)), then sleep // until `next` or RX-ready... } ``` -------------------------------- ### Initialize Tracing Subscriber Source: https://github.com/al8n/hick/blob/main/README.md Install a tracing subscriber in your main function to enable structured events and spans. This is required when the 'tracing' feature is enabled. ```rust fn main() { tracing_subscriber::fmt().init(); // … start your endpoint … } ``` -------------------------------- ### Tokio Runtime Service Registration and Discovery with Hick Source: https://github.com/al8n/hick/blob/main/README.md This snippet shows how to start the Hick driver on Tokio, register a service with its details (name, host, port, TTL), and then discover services of a specific type. Ensure the service handle is kept alive to maintain registration. The discovery loop prints answers and terminates on a terminal event. ```rust use hick::{Name, QuerySpec, ServiceRecords, ServiceSpec, wire::ResourceType}; use hick::tokio::{server, QueryEvent, ServerOptions}; #[tokio::main] async fn main() -> Result<(), Box> { // Start the driver, pinned to the tokio runtime. let endpoint = server(ServerOptions::default()).await?; // Advertise a service. Keep the returned handle alive to keep advertising; // dropping it withdraws the service (TTL=0 goodbye) and unregisters it. let mut records = ServiceRecords::new( Name::try_from_str("_http._tcp.local.")?, Name::try_from_str("My Device._http._tcp.local.")?, Name::try_from_str("my-device.local.")?, 80, 120, ); records.add_a([192, 168, 1, 10].into()); let _service = endpoint.register_service(ServiceSpec::new(records)).await?; // Discover services of a type on the local link. let mut query = endpoint .start_query(QuerySpec::new( Name::try_from_str("_ipp._tcp.local.")?, ResourceType::Ptr, )) .await?; while let Some(event) = query.next().await { match event { QueryEvent::Answer(answer) => println!("{answer:?}"), QueryEvent::Terminal(_) => break, } } Ok(()) } ``` -------------------------------- ### Hick Installation for Bare-Metal without Native Atomic CAS Source: https://github.com/al8n/hick/blob/main/README.md For cores without native atomic CAS, use the 'embassy-no-atomic' tier. This swaps refcounted data onto 'portable-atomic' and requires a 'critical-section' implementation. ```toml [dependencies] hick = { version = "0.1", default-features = false, features = ["embassy-no-atomic"] } ``` -------------------------------- ### Enable Defmt and Stats Features Source: https://github.com/al8n/hick/blob/main/hick-smoltcp/README.md Configure the hick-smoltcp dependency in your Cargo.toml to enable defmt for logging and stats for performance counters. This is the recommended setup for bare-metal targets. ```toml hick-smoltcp = { version = "0.1", features = ["defmt", "stats"] } ``` -------------------------------- ### Hick Installation for Bare-Metal with Embassy Source: https://github.com/al8n/hick/blob/main/README.md Configure 'hick' for bare-metal targets using the 'embassy' async driver by disabling default features and enabling the 'embassy' feature. This configuration does not pull in 'std'. ```toml [dependencies] hick = { version = "0.1", default-features = false, features = ["embassy"] } ``` -------------------------------- ### Enable Stats Feature and Get Snapshot Source: https://github.com/al8n/hick/blob/main/hick-compio/README.md Enable the 'stats' feature to obtain atomic counters. A snapshot can be read via endpoint.stats(). ```rust features = ["stats"] ``` ```rust let snap = endpoint.stats(); println!("packets_rx={} services_active={}", snap.packets_rx, snap.services_active); ``` -------------------------------- ### Get Engine Statistics Snapshot Source: https://github.com/al8n/hick/blob/main/hick-smoltcp/README.md Call the `engine.stats()` method to retrieve a snapshot of performance statistics. This requires the `stats` feature to be enabled. ```rust let snap = engine.stats(); // snap.packets_rx, snap.cache_size, etc. ``` -------------------------------- ### Get Stats Snapshot Source: https://github.com/al8n/hick/blob/main/README.md Enable the 'stats' feature to poll counters without a full metrics exporter. Call endpoint.stats() to retrieve a snapshot of statistics. ```rust use hick::tokio::{server, ServerOptions}; let endpoint = server(ServerOptions::default()).await?; // … run for a while … let snap = endpoint.stats(); println!("rx={} tx={} cache_size={}", snap.packets_rx, snap.packets_tx, snap.cache_size); ``` -------------------------------- ### Get Stats Snapshot in Rust Source: https://github.com/al8n/hick/blob/main/hick-embassy/README.md Call `state.stats()` to obtain a `hick_trace::stats::StatsSnapshot` for observability on embedded systems. This requires the `stats` feature to be enabled. ```rust let snap = state.stats(); // snap.packets_rx, snap.services_active, snap.cache_size, etc. ``` -------------------------------- ### Initialize and Register mDNS Service Source: https://github.com/al8n/hick/blob/main/hick-embassy/README.md Initialize the MdnsState and register a service to be advertised. Ensure the state is shared safely across tasks. ```rust use hick_embassy::MdnsState; use mdns_proto::{EndpointConfig, Name, ServiceRecords, ServiceSpec}; let state: &'static MdnsState<_> = make_static!(MdnsState::new(EndpointConfig::new(), rng)); // Advertise a service. let mut records = ServiceRecords::new( Name::try_from_str("_http._tcp.local.").unwrap(), Name::try_from_str("My Device._http._tcp.local.").unwrap(), Name::try_from_str("mydevice.local.").unwrap(), 80, 120, ); records.add_a(my_ipv4_addr); state.register_service(ServiceSpec::new(records)).unwrap(); ``` -------------------------------- ### Enable tracing for mdns-proto Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Enable the 'tracing' feature to emit structured tracing events. A tracing subscriber must be initialized in your application. ```rust tracing_subscriber::fmt().init(); ``` -------------------------------- ### Add hick-smoltcp Dependency Source: https://github.com/al8n/hick/blob/main/hick-smoltcp/README.md Add the hick-smoltcp crate to your project's dependencies. ```toml [dependencies] hick-smoltcp = "0.1" ``` -------------------------------- ### Spawn mDNS Driver Task Source: https://github.com/al8n/hick/blob/main/hick-embassy/README.md Bind UDP sockets, join mDNS groups, and spawn the asynchronous mDNS driver task. The driver handles egress hop limits. ```rust // Bind v4/v6 sockets to :5353 and join the mDNS group(s), then spawn the driver task // (it enforces the RFC 6762 §11 egress hop-limit 255 itself — pass sockets by &mut): spawner.must_spawn(mdns_task(state, v4_socket, v6_socket, scratch)); #[embassy_executor::task] async fn mdns_task( state: &'static MdnsState, v4: &'static mut UdpSocket<'static>, v6: &'static mut UdpSocket<'static>, scratch: &'static mut [u8], ) -> ! { state.run(Some(v4), Some(v6), scratch).await } ``` -------------------------------- ### Enable Metrics Feature Source: https://github.com/al8n/hick/blob/main/hick-compio/README.md Enable the 'metrics' feature to forward counter and gauge updates to the 'metrics' facade automatically. This implies the 'stats' feature is also enabled. ```rust features = ["metrics"] ``` -------------------------------- ### Add hick-udp to Cargo.toml Source: https://github.com/al8n/hick/blob/main/hick-udp/README.md Add this line to your Cargo.toml file to include hick-udp as a dependency. ```toml [dependencies] hick-udp = "0.5" ``` -------------------------------- ### Enable Defmt and Stats Features for Hick Embassy Source: https://github.com/al8n/hick/blob/main/hick-embassy/README.md Add this to your Cargo.toml to enable `defmt` for structured logging and `stats` for atomic counters on embassy targets. ```toml hick-embassy = { version = "0.1", features = ["defmt", "stats"] } ``` -------------------------------- ### Add hick-reactor Dependency (Tokio) Source: https://github.com/al8n/hick/blob/main/hick-reactor/README.md Include the hick-reactor crate in your project's Cargo.toml file. This configuration defaults to using the tokio runtime. ```toml [dependencies] hick-reactor = "0.6" ``` -------------------------------- ### Enable Tracing Feature Source: https://github.com/al8n/hick/blob/main/hick-compio/README.md Enable the 'tracing' feature to emit tracing events during socket I/O, service probing, and query state transitions. ```rust features = ["tracing"] ``` -------------------------------- ### Add hick-compio Dependency Source: https://github.com/al8n/hick/blob/main/hick-compio/README.md Add this to your Cargo.toml to include hick-compio in your project. ```toml [dependencies] hick-compio = "0.1" ``` -------------------------------- ### Enable Stats Snapshot Source: https://github.com/al8n/hick/blob/main/hick-reactor/README.md Enable the 'stats' feature to use endpoint.stats() for obtaining a StatsSnapshot. This allows you to access metrics like packets received and active queries. ```rust let snap = endpoint.stats(); println!("packets_rx={} queries_active={}", snap.packets_rx, snap.queries_active); ``` -------------------------------- ### Add hick-reactor Dependency (Smol) Source: https://github.com/al8n/hick/blob/main/hick-reactor/README.md To use hick-reactor with the smol runtime instead of tokio, specify the 'smol' feature and disable default features in your Cargo.toml. ```toml [dependencies] hick-reactor = { version = "0.6", default-features = false, features = ["smol"] } ``` -------------------------------- ### Accessing mdns-proto statistics Source: https://github.com/al8n/hick/blob/main/mdns-proto/README.md Enable the 'stats' feature (requires alloc) to access atomic counters. The StatsSnapshot struct provides various packet and cache statistics. ```rust let snap = endpoint.stats(); println!("packets_rx={} cache_size={}", snap.packets_rx, snap.cache_size); ``` -------------------------------- ### Add hick-embassy Dependency Source: https://github.com/al8n/hick/blob/main/hick-embassy/README.md Add the hick-embassy crate to your project's dependencies in Cargo.toml. ```toml [dependencies] hick-embassy = "0.1" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.