Skip to content

Commit 3d2c951

Browse files
authored
feat: add missing constructors for non-exhaustive model types (#739)
* feat: add constructors for Root and ListRootsResult * feat: add constructors for UnsubscribeRequestParams and PromptReference
1 parent 656a09a commit 3d2c951

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

crates/rmcp/src/model.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,16 @@ pub struct UnsubscribeRequestParams {
12621262
pub uri: String,
12631263
}
12641264

1265+
impl UnsubscribeRequestParams {
1266+
/// Creates a new `UnsubscribeRequestParams` for the given URI.
1267+
pub fn new(uri: impl Into<String>) -> Self {
1268+
Self {
1269+
meta: None,
1270+
uri: uri.into(),
1271+
}
1272+
}
1273+
}
1274+
12651275
impl RequestParamsMeta for UnsubscribeRequestParams {
12661276
fn meta(&self) -> Option<&Meta> {
12671277
self.meta.as_ref()
@@ -2356,6 +2366,22 @@ pub struct PromptReference {
23562366
pub title: Option<String>,
23572367
}
23582368

2369+
impl PromptReference {
2370+
/// Creates a new `PromptReference` with the given name. `title` defaults to `None`.
2371+
pub fn new(name: impl Into<String>) -> Self {
2372+
Self {
2373+
name: name.into(),
2374+
title: None,
2375+
}
2376+
}
2377+
2378+
/// Sets the human-readable title for this prompt reference.
2379+
pub fn with_title(mut self, title: impl Into<String>) -> Self {
2380+
self.title = Some(title.into());
2381+
self
2382+
}
2383+
}
2384+
23592385
const_string!(CompleteRequestMethod = "completion/complete");
23602386
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
23612387
#[serde(rename_all = "camelCase")]
@@ -2378,6 +2404,22 @@ pub struct Root {
23782404
pub name: Option<String>,
23792405
}
23802406

2407+
impl Root {
2408+
/// Creates a new `Root` with the given URI. `name` defaults to `None`.
2409+
pub fn new(uri: impl Into<String>) -> Self {
2410+
Self {
2411+
uri: uri.into(),
2412+
name: None,
2413+
}
2414+
}
2415+
2416+
/// Sets the human-readable name for this root.
2417+
pub fn with_name(mut self, name: impl Into<String>) -> Self {
2418+
self.name = Some(name.into());
2419+
self
2420+
}
2421+
}
2422+
23812423
const_string!(ListRootsRequestMethod = "roots/list");
23822424
pub type ListRootsRequest = RequestNoParam<ListRootsRequestMethod>;
23832425

@@ -2389,6 +2431,13 @@ pub struct ListRootsResult {
23892431
pub roots: Vec<Root>,
23902432
}
23912433

2434+
impl ListRootsResult {
2435+
/// Creates a new `ListRootsResult` with the given roots.
2436+
pub fn new(roots: Vec<Root>) -> Self {
2437+
Self { roots }
2438+
}
2439+
}
2440+
23922441
const_string!(RootsListChangedNotificationMethod = "notifications/roots/list_changed");
23932442
pub type RootsListChangedNotification = NotificationNoParam<RootsListChangedNotificationMethod>;
23942443

0 commit comments

Comments
 (0)