use crate::places_new::autocomplete::{Response, Request, Suggestion};
#[derive(
//std
Clone,
Debug,
// serde
serde::Serialize,
// getset
getset::Getters,
getset::MutGetters,
getset::Setters,
)]
pub struct ResponseWithContext {
#[getset(get = "pub")]
pub response: Response,
#[getset(get = "pub", set = "pub", get_mut = "pub")]
pub request: Request,
}
impl ResponseWithContext {
#[must_use]
pub const fn new(response: Response, request: Request) -> Self {
Self { response, request }
}
#[must_use]
pub fn continue_with(self, new_input: impl Into<String>) -> Request {
let mut next_request = self.request;
next_request.set_input(new_input.into());
next_request
}
#[must_use]
pub fn into_parts(self) -> (Response, Request) {
(self.response, self.request)
}
#[must_use]
pub fn into_response(self) -> Response {
self.response
}
#[must_use]
pub fn into_request(self) -> Request {
self.request
}
}
impl std::ops::Deref for ResponseWithContext {
type Target = Response;
fn deref(&self) -> &Self::Target {
&self.response
}
}
impl std::ops::DerefMut for ResponseWithContext {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.response
}
}
impl std::ops::Index<usize> for ResponseWithContext {
type Output = Suggestion;
fn index(&self, index: usize) -> &Self::Output {
&self.response.suggestions[index]
}
}
impl std::ops::IndexMut<usize> for ResponseWithContext {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.response.suggestions[index]
}
}
impl AsRef<[Suggestion]> for ResponseWithContext {
fn as_ref(&self) -> &[Suggestion] {
&self.response.suggestions
}
}
impl AsMut<[Suggestion]> for ResponseWithContext {
fn as_mut(&mut self) -> &mut [Suggestion] {
&mut self.response.suggestions
}
}
impl IntoIterator for ResponseWithContext {
type Item = Suggestion;
type IntoIter = std::vec::IntoIter<Suggestion>;
fn into_iter(self) -> Self::IntoIter {
self.response.suggestions.into_iter()
}
}
impl<'a> IntoIterator for &'a ResponseWithContext {
type Item = &'a Suggestion;
type IntoIter = std::slice::Iter<'a, Suggestion>;
fn into_iter(self) -> Self::IntoIter {
self.response.suggestions.iter()
}
}
impl<'a> IntoIterator for &'a mut ResponseWithContext {
type Item = &'a mut Suggestion;
type IntoIter = std::slice::IterMut<'a, Suggestion>;
fn into_iter(self) -> Self::IntoIter {
self.response.suggestions.iter_mut()
}
}
impl ResponseWithContext {
pub fn iter(&self) -> std::slice::Iter<'_, Suggestion> {
self.response.suggestions.iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, Suggestion> {
self.response.suggestions.iter_mut()
}
}