Skip to content

Tracking Issue for SyncView #98407

@guswynn

Description

@guswynn

View all comments

Feature gate: #![feature(exclusive_wrapper)]

This is a tracking issue for the SyncView wrapper struct.

This structure can be used to upgrade non-Sync objects into Sync ones, by only offering mutable access to the underlying object. This can be useful with Send-but-not-Sync futures (like BoxFutures)

Public API

// core::sync
#[derive(Default)]
struct SyncView<T: ?Sized> { ... }

unsafe impl<T: ?Sized> Sync for SyncView<T> {}
// via auto traits:
// unsafe impl<T: ?Sized + Send> Send for SyncView<T> {}

impl<T> SyncView<T> {
    pub const fn new(x: T) -> Self;
    pub const fn into_inner(self) -> T;
}

impl<T: ?Sized> SyncView<T> {
    pub const fn as_pin(self: Pin<&Self>) -> Pin<&T>;
    pub const fn as_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>;
    pub const fn from_mut(x: &mut T) -> &mut Self;
    pub const fn from_pin_mut(x: Pin<&mut T>) -> Pin<&mut Self>;
}

impl<T> From<T> for SyncView<T> { ... }

impl<T: ?Sized + Sync> AsRef<T> for SyncView<T> { ... }
impl<T: ?Sized> AsMut<T> for SyncView<T> { ... }

// Unconditionally implemented regardless of `T: Sync`:
impl<T: ?Sized> Debug for SyncView<T> { ... }

// + a bunch of forwarding impls (Clone, Copy, PartialEq, FnOnce,
// Future etc.) that require `Sync` when impl uses `&self`, and
// not when impl uses `&mut self`.
//
// Not yet `Iterator`, that has both `&self` and `&mut self` methods.

Steps / History

Unresolved Questions

  • Figure out naming.
  • Bikeshed certain method names (as_pin versus as_pin_ref comes to mind).
  • Address the issue with the documentation example that was pointed out in Example for std::sync::SyncView is dubious #146245.
  • Decide on the fate of the impl Debug (currently, the only nontrivial API surface that &SyncView<impl ?Sync> unconditionally implements).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions