melvin_ob/http_handler/http_response/
beacon_position.rs

1use crate::http_handler::http_response::response_common::SerdeJSONBodyHTTPResponseType;
2
3/// Response type for the /beacon endpoint
4#[derive(serde::Deserialize, Debug)]
5pub(crate) struct BeaconPositionResponse {
6    /// Status of the Beacon
7    status: String,
8    /// Already made attempts for guessing the position of this beacon
9    attempts_made: i8,
10}
11
12impl BeaconPositionResponse {
13    /// `true` if the message indicates that the beacon was correctly located
14    pub(crate) fn is_success(&self) -> bool { self.status.contains("The beacon was found!") }
15    /// Returns the number of guesses that were already submitted
16    pub(crate) fn attempts_made(&self) -> i8 { self.attempts_made }
17    /// `true` if the beacon objective is not known to the server
18    pub(crate) fn is_unknown(&self) -> bool { self.status.contains("Could not find beacon") }
19    /// `true` if the beacon could not be correctly located
20    pub(crate) fn is_fail(&self) -> bool { self.status.contains("The beacon could not be found") }
21    /// `true` if the beacon could not be correctly located and this was the last possible guess
22    pub(crate) fn is_last(&self) -> bool { self.status.contains("No more rescue attempts") }
23    /// Returns the raw status message
24    pub(crate) fn msg(&self) -> &str { &self.status }
25}
26
27impl SerdeJSONBodyHTTPResponseType for BeaconPositionResponse {}