[−][src]Enum gtp::Response
Represents a GTP response from the GTP engine.
Variants
Error((Option<u32>, String))
Result((Option<u32>, String))
Methods
impl Response
[src]
pub fn text(&self) -> String
[src]
Returns the complete response text, which you may feed into EntityParser.
See also the Response::entities
method.
pub fn id_0(&self) -> u32
[src]
Returns the ID of the response. Returns 0 if no ID was submitted.
pub fn entities<T>(
&self,
parse_fn: T
) -> Result<Vec<Entity>, ResponseParseError> where
T: Fn(&mut EntityParser) -> &mut EntityParser,
[src]
&self,
parse_fn: T
) -> Result<Vec<Entity>, ResponseParseError> where
T: Fn(&mut EntityParser) -> &mut EntityParser,
Parses entities from a Response
let mut rp = gtp::ResponseParser::new(); rp.feed("= 10 w H6\n\n"); let entity_vec = rp.get_response().unwrap() .entities(|ep| ep.i().mv()) .unwrap(); assert_eq!(format!("{:?}", entity_vec), "[Int(10), Move((W, (8, 6)))]"); if let gtp::Entity::Int(i) = entity_vec[0] { assert_eq!(i, 10); }
Here is an example for how to read a variable length list:
let mut rp = gtp::ResponseParser::new(); rp.feed("= A\nB\nC\nD\nE\n\n"); let entity_vec = rp.get_response().unwrap() .entities(|ep| { while !ep.is_eof() { ep.s(); }; ep }) .unwrap(); assert_eq!(format!("{:?}", entity_vec), "[String(\"A\"), String(\"B\"), String(\"C\"), String(\"D\"), String(\"E\")]");
Trait Implementations
impl Clone for Response
[src]
fn clone(&self) -> Response
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<Response> for Response
[src]
impl Debug for Response
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,