Struct Client

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

The base kRPC client type.

§Connecting to the kRPC server

Call new to establish a connection with the kRPC server.

use krpc_client::Client;
let client = Client::new("Test KRPC", "127.0.0.1", 50000, 50001);

§Using RPC services

Pass or clone the client instance returned by Client::new to any RPC service in krpc_client::services::*.

use krpc_client::{services::space_center::SpaceCenter, Client};
let space_center = SpaceCenter::new(client);
// Then call procedures with the created service.
println!("Hello, {}!", space_center.get_active_vessel()?.get_name()?);

Implementations§

Source§

impl Client

Source

pub fn new( name: &str, ip_addr: &str, rpc_port: u16, stream_port: u16, ) -> Result<Arc<Self>, RpcError>

Constructs a new Client.

§Examples
use krpc_client::Client;
let client = Client::new("Test KRPC", "127.0.0.1", 50000, 50001);
Examples found in repository?
examples/streams.rs (line 8)
7fn main() -> Result<(), Box<dyn Error>> {
8    let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10    let space_center = SpaceCenter::new(client.clone());
11
12    // Set up a stream.
13    let ut_stream = space_center.get_ut_stream()?;
14    ut_stream.set_rate(1f32)?;
15
16    // Wait for updates, and print the current value.
17    for _ in 0..10 {
18        ut_stream.wait();
19        println!("It's {} o'clock", ut_stream.get()?);
20    }
21
22    Ok(())
23}
More examples
Hide additional examples
examples/client.rs (line 8)
7fn main() -> Result<(), Box<dyn Error>> {
8    let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001).unwrap();
9
10    let sc = SpaceCenter::new(client.clone());
11
12    // Check out our vessel.
13    let ship = sc.get_active_vessel()?;
14
15    // Greet the crew.
16    match ship.get_crew()?.first() {
17        Some(kerbal) => println!(
18            "Hello, {}. Welcome to {}",
19            kerbal.get_name()?,
20            ship.get_name()?
21        ),
22        None => println!("{} is unkerbaled!", ship.get_name()?),
23    };
24
25    Ok(())
26}

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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> 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, 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.