[−][src]Struct f1_api::F1
A high-level interface to the telemetry data of modern F1 video games.
The F1 struct implements a high-level interface to the telemetry data of the modern F1 video games. It is the recommended way to use the library, as it provides a simple interface to consumers that hides the low-level internals of the library.
Methods
impl F1
[src]
pub fn stream(
socket_address: SocketAddr
) -> Result<impl Stream<Item = Packet>, Error>
[src]
socket_address: SocketAddr
) -> Result<impl Stream<Item = Packet>, Error>
Create a stream that yields decoded UDP packets.
Modern F1 games publish their telemetry and session data through a UDP-based protocol. With
this function, a stream can be created that listens at the given socket for incoming
packets, decodes them using the F1Codec
, and returns their Rust representations.
Examples
use f1_api::F1; use f1_api::packet::Packet::{Event, Lap, Motion, Participants, Session, Setup, Status, Telemetry}; use std::net::{IpAddr, SocketAddr}; use tokio::stream::StreamExt; async fn example() { let ip_address = IpAddr::from([0, 0, 0, 0]); let port = 20777; let socket = SocketAddr::new(ip_address, port); let mut stream = F1::stream(socket).unwrap(); while let Some(packet) = stream.next().await { match packet { Event(_) => println!("Received Event packet"), Lap(_) => println!("Received Lap packet"), Motion(_) => println!("Received Motion packet"), Participants(_) => println!("Received Participants packet"), Session(_) => println!("Received Session packet"), Setup(_) => println!("Received Setup packet"), Status(_) => println!("Received Status packet"), Telemetry(_) => println!("Received Telemetry packet"), } } }
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,