Skip to content

Commit

Permalink
chore: improve document
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Sep 4, 2023
1 parent 88104cb commit 4b2a0be
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/conn/quinn/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::http::Version;
use super::H3Connection;
use crate::conn::{Accepted, Acceptor, Listener};

/// QuinnListener
/// A wrapper of `Listener` with quinn.
pub struct QuinnListener<S, C, T, E> {
config_stream: S,
local_addr: T,
Expand Down Expand Up @@ -68,7 +68,7 @@ where
}
}

/// QuinnAcceptor
/// A wrapper of `Acceptor` with quinn.
pub struct QuinnAcceptor<S, C, E> {
config_stream: S,
socket: SocketAddr,
Expand Down
11 changes: 7 additions & 4 deletions crates/core/src/conn/rustls/listener.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! rustls module
use std::error::Error as StdError;
use std::io::{Error as IoError, ErrorKind, Result as IoResult};
use std::marker::PhantomData;
use std::error::Error as StdError;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
Expand All @@ -19,7 +19,8 @@ use crate::http::Version;

use super::ServerConfig;

/// RustlsListener

/// A wrapper of `Listener` with rustls.
pub struct RustlsListener<S, C, T, E> {
config_stream: S,
inner: T,
Expand Down Expand Up @@ -63,7 +64,7 @@ where
}
}

/// RustlsAcceptor
/// A wrapper of `Acceptor` with rustls.
pub struct RustlsAcceptor<S, C, T, E> {
config_stream: S,
inner: T,
Expand Down Expand Up @@ -137,7 +138,9 @@ where
config
};
if let Some(config) = config {
let config: ServerConfig = config.try_into().map_err(|e| IoError::new(ErrorKind::Other, e.to_string()))?;
let config: ServerConfig = config
.try_into()
.map_err(|e| IoError::new(ErrorKind::Other, e.to_string()))?;
let tls_acceptor = tokio_rustls::TlsAcceptor::from(Arc::new(config));
if self.tls_acceptor.is_some() {
tracing::info!("tls config changed.");
Expand Down
41 changes: 41 additions & 0 deletions crates/oapi-macros/src/feature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,44 @@ impl Merge<Vec<Feature>> for Vec<Feature> {
self
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_merge_with_empty_vec() {
let vec1 = vec![Feature::new("feature1"), Feature::new("feature2")];
let vec2 = vec![];
let merged = vec1.clone().merge(vec2.clone());
assert_eq!(merged, vec1);
let merged = vec2.clone().merge(vec1.clone());
assert_eq!(merged, vec1);
}

#[test]
fn test_merge_with_non_empty_vec() {
let vec1 = vec![Feature::new("feature1"), Feature::new("feature2")];
let vec2 = vec![Feature::new("feature3"), Feature::new("feature4")];
let merged = vec1.clone().merge(vec2.clone());
assert_eq!(
merged,
vec![
Feature::new("feature1"),
Feature::new("feature2"),
Feature::new("feature3"),
Feature::new("feature4")
]
);
let merged = vec2.clone().merge(vec1.clone());
assert_eq!(
merged,
vec![
Feature::new("feature3"),
Feature::new("feature4"),
Feature::new("feature1"),
Feature::new("feature2")
]
);
}
}

0 comments on commit 4b2a0be

Please sign in to comment.