use crate::places_new::Place;
use crate::places_new::text_search::{Response, Request};
#[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 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 = Place;
fn index(&self, index: usize) -> &Self::Output {
&self.response.places[index]
}
}
impl std::ops::IndexMut<usize> for ResponseWithContext {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.response.places[index]
}
}
impl AsRef<[Place]> for ResponseWithContext {
fn as_ref(&self) -> &[Place] {
&self.response.places
}
}
impl AsMut<[Place]> for ResponseWithContext {
fn as_mut(&mut self) -> &mut [Place] {
&mut self.response.places
}
}
impl IntoIterator for ResponseWithContext {
type Item = Place;
type IntoIter = std::vec::IntoIter<Place>;
fn into_iter(self) -> Self::IntoIter {
self.response.places.into_iter()
}
}
impl<'a> IntoIterator for &'a ResponseWithContext {
type Item = &'a Place;
type IntoIter = std::slice::Iter<'a, Place>;
fn into_iter(self) -> Self::IntoIter {
self.response.places.iter()
}
}
impl<'a> IntoIterator for &'a mut ResponseWithContext {
type Item = &'a mut Place;
type IntoIter = std::slice::IterMut<'a, Place>;
fn into_iter(self) -> Self::IntoIter {
self.response.places.iter_mut()
}
}
impl ResponseWithContext {
pub fn iter(&self) -> std::slice::Iter<'_, Place> {
self.response.places.iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, Place> {
self.response.places.iter_mut()
}
}