chore: add #[non_exhaustive] to remaining public structs (#768)

* chore: add #[non_exhaustive] to remaining public structs

* chore: add #[non_exhaustive] to remaining public types

* chore: enable exhaustive_structs/enums clippy lints

* test: add untagged ServerResult deserialization regression tests
This commit is contained in:
Dale Seo 2026-03-26 10:23:58 -04:00 • committed by GitHub
commit 6a3b32d3ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 430 additions and 211 deletions

View file

@ -29,12 +29,14 @@ use crate::{
};
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct LocalSessionManager {
pub sessions: tokio::sync::RwLock<HashMap<SessionId, LocalSessionHandle>>,
pub session_config: SessionConfig,
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum LocalSessionManagerError {
#[error("Session not found: {0}")]
SessionNotFound(SessionId),
@ -148,6 +150,7 @@ impl std::fmt::Display for EventId {
}
#[derive(Debug, Clone, Error)]
#[non_exhaustive]
pub enum EventIdParseError {
#[error("Invalid index: {0}")]
InvalidIndex(ParseIntError),
@ -310,6 +313,7 @@ impl LocalSessionWorker {
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum SessionError {
#[error("Invalid request id: {0}")]
DuplicatedRequestId(HttpRequestId),
@ -339,6 +343,7 @@ enum OutboundChannel {
Common,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct StreamableHttpMessageReceiver {
pub http_request_id: Option<HttpRequestId>,
pub inner: Receiver<ServerSseMessage>,
@ -657,6 +662,7 @@ impl LocalSessionWorker {
}
#[derive(Debug)]
#[non_exhaustive]
pub enum SessionEvent {
ClientMessage {
message: ClientJsonRpcMessage,
@ -1059,6 +1065,7 @@ impl Worker for LocalSessionWorker {
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SessionConfig {
/// the capacity of the channel for the session. Default is 16.
pub channel_capacity: usize,

View file

@ -10,9 +10,12 @@ use crate::{
#[derive(Debug, Clone, Error)]
#[error("Session management is not supported")]
#[non_exhaustive]
pub struct ErrorSessionManagementNotSupported;
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct NeverSessionManager {}
#[non_exhaustive]
pub enum NeverTransport {}
impl Transport<RoleServer> for NeverTransport {
type Error = ErrorSessionManagementNotSupported;

View file

@ -30,6 +30,7 @@ use crate::{
};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct StreamableHttpServerConfig {
/// The ping message duration for SSE connections.
pub sse_keep_alive: Option<Duration>,
@ -62,6 +63,33 @@ impl Default for StreamableHttpServerConfig {
}
}
impl StreamableHttpServerConfig {
pub fn with_sse_keep_alive(mut self, duration: Option<Duration>) -> Self {
self.sse_keep_alive = duration;
self
}
pub fn with_sse_retry(mut self, duration: Option<Duration>) -> Self {
self.sse_retry = duration;
self
}
pub fn with_stateful_mode(mut self, stateful: bool) -> Self {
self.stateful_mode = stateful;
self
}
pub fn with_json_response(mut self, json_response: bool) -> Self {
self.json_response = json_response;
self
}
pub fn with_cancellation_token(mut self, token: CancellationToken) -> Self {
self.cancellation_token = token;
self
}
}
#[expect(
clippy::result_large_err,
reason = "BoxResponse is intentionally large; matches other handlers in this file"