wireman_core/descriptor/
reflection_request.rs1use super::metadata::Metadata;
2use crate::error::{Error, Result};
3use tonic::metadata::{Ascii, MetadataKey, MetadataValue};
4
5#[derive(Debug, Clone)]
7pub struct ReflectionRequest {
8 pub host: String,
10 pub metadata: Option<Metadata>,
12}
13
14impl ReflectionRequest {
15 #[must_use]
17 pub fn new(host: &str) -> Self {
18 Self {
19 host: host.to_string(),
20 metadata: None,
21 }
22 }
23
24 pub fn insert_metadata(&mut self, key: &str, val: &str) -> Result<()> {
30 let key: MetadataKey<Ascii> = key.parse().map_err(|_| Error::ParseToAsciiError)?;
31 let val: MetadataValue<Ascii> = val.parse().map_err(|_| Error::ParseToAsciiError)?;
32 let map = self.metadata.get_or_insert(Metadata::new());
33 map.insert(key, val);
34 Ok(())
35 }
36}