Skip to content

Commit

Permalink
desktop: Make trait SessionPortal public
Browse files Browse the repository at this point in the history
Make SessionPortal public so that users can use it in bounds
Apply the sealed trait trick so that users are unable to implement it
  • Loading branch information
dimtpap authored and bilelmoussaoui committed Sep 15, 2024
1 parent 97ca83e commit a82a4e3
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/desktop/global_shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ impl<'a> std::ops::Deref for GlobalShortcuts<'a> {
}
}

impl crate::Sealed for GlobalShortcuts<'_> {}
impl SessionPortal for GlobalShortcuts<'_> {}
1 change: 1 addition & 0 deletions src/desktop/inhibit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,5 @@ impl<'a> std::ops::Deref for InhibitProxy<'a> {
}
}

impl crate::Sealed for InhibitProxy<'_> {}
impl SessionPortal for InhibitProxy<'_> {}
1 change: 1 addition & 0 deletions src/desktop/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,5 @@ impl<'a> std::ops::Deref for InputCapture<'a> {
}
}

impl crate::Sealed for InputCapture<'_> {}
impl SessionPortal for InputCapture<'_> {}
1 change: 1 addition & 0 deletions src/desktop/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl<'a> LocationProxy<'a> {
}
}

impl crate::Sealed for LocationProxy<'_> {}
impl SessionPortal for LocationProxy<'_> {}

impl<'a> std::ops::Deref for LocationProxy<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod session;
pub(crate) use self::handle_token::HandleToken;
pub use self::{
request::{Request, Response, ResponseError, ResponseType},
session::Session,
session::{Session, SessionPortal},
};
mod color;
pub use color::Color;
Expand Down
1 change: 1 addition & 0 deletions src/desktop/remote_desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,5 @@ impl<'a> std::ops::Deref for RemoteDesktop<'a> {
}
}

impl crate::Sealed for RemoteDesktop<'_> {}
impl SessionPortal for RemoteDesktop<'_> {}
1 change: 1 addition & 0 deletions src/desktop/screencast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ impl<'a> std::ops::Deref for Screencast<'a> {
}
}

impl crate::Sealed for Screencast<'_> {}
impl SessionPortal for Screencast<'_> {}

/// Defines which portals session can be used in a screen-cast.
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
}

/// Portals that have a long-lived interaction
pub trait SessionPortal {}
pub trait SessionPortal: crate::Sealed {}

/// A response to a `create_session` request.
#[derive(Type, Debug)]
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ pub async fn is_sandboxed() -> bool {
}

pub use self::error::{Error, PortalError};

mod sealed {
/// Use as a supertrait for public traits that users should not be able to implement
pub trait Sealed {}
}

pub(crate) use sealed::Sealed;

0 comments on commit a82a4e3

Please sign in to comment.