Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Configuration for a NETCONF session.

Use Config::builder() for a fluent API, or Config::default() for sensible defaults.

§Example

use std::time::Duration;
use netconf_rust::Config;

let config = Config::builder()
    .hello_timeout(Duration::from_secs(10))
    .connect_timeout(Duration::from_secs(5))
    .nodelay(true)
    .build();

Implementations§

Source§

impl Config

Source

pub fn builder() -> ConfigBuilder

Examples found in repository?
examples/disconnect_watcher.rs (line 8)
7async fn main() -> netconf_rust::Result<()> {
8    let config = Config::builder()
9        .keepalive_interval(Duration::from_secs(10))
10        .keepalive_max(3)
11        .rpc_timeout(Duration::from_secs(30))
12        .connect_timeout(Duration::from_secs(10))
13        .nodelay(true)
14        .build();
15
16    let session = Arc::new(
17        Session::connect_with_config("localhost", 830, "netconf", "netconf", config).await?,
18    );
19
20    println!("Connected (session {})", session.session_id());
21
22    // Spawn a background task that fires when the session disconnects.
23    // This is the pattern you'd use in a long-running service to clean up
24    // sessions from a DashMap or similar structure.
25    let watcher_session = Arc::clone(&session);
26    let watcher = tokio::spawn(async move {
27        let reason = watcher_session.disconnected().await;
28        println!("Disconnect detected: {reason}");
29        // In a real service you'd remove the session from your map here:
30        //   sessions.remove(&uuid);
31    });
32
33    // Normal operations — the watcher runs in the background
34    let config = session
35        .get_config(netconf_rust::Datastore::Running, None)
36        .await?;
37    println!("Got config ({} bytes)", config.len());
38
39    // You can also race an RPC against disconnect using select!
40    tokio::select! {
41        result = session.get_config(netconf_rust::Datastore::Running, None) => {
42            match result {
43                Ok(data) => println!("Got config again ({} bytes)", data.len()),
44                Err(e) => eprintln!("RPC failed: {e}"),
45            }
46        }
47        reason = session.disconnected() => {
48            eprintln!("Connection lost while waiting for RPC: {reason}");
49        }
50    }
51
52    // Graceful close — the watcher will fire with DisconnectReason::Eof
53    // after the server acknowledges the close and drops the connection.
54    session.close_session().await?;
55    println!("Session closed");
56
57    // Wait for the watcher to complete
58    let _ = watcher.await;
59
60    Ok(())
61}
Source

pub fn max_message_size(&self) -> Option<usize>

Maximum message size limit, or None for unlimited.

Source

pub fn connect_timeout(&self) -> Option<Duration>

Timeout for the TCP/SSH connect phase.

Source

pub fn hello_timeout(&self) -> Option<Duration>

Timeout for the NETCONF hello exchange.

Source

pub fn rpc_timeout(&self) -> Option<Duration>

Timeout for individual RPC operations.

Source

pub fn window_size(&self) -> u32

SSH flow-control window size.

Returns the configured value, or DEFAULT_WINDOW_SIZE if not set.

Source

pub fn maximum_packet_size(&self) -> u32

Maximum SSH packet size.

Returns the configured value, or DEFAULT_MAXIMUM_PACKET_SIZE if not set.

Source

pub fn stream_buffer_capacity(&self) -> usize

Capacity of the internal channel used by streaming RPCs.

Source

pub fn lenient_chunked_framing(&self) -> LenientChunkedFraming

Lenient chunked framing recovery mode.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V