-
-
Save rust-play/d3a0afca92d2b4ed30436712cfc62dd8 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DefaultValueMarker; | |
struct DefaultFunctionMarker; | |
trait GcResourceMutability {} | |
// Immutable GC resources can only be immutably borrowed, but both in sync and | |
// async ops. | |
struct GcResourceImmutable; | |
impl GcResourceMutability for GcResourceImmutable {} | |
// Mutable GC resources can both be immutably and mutably borrowed, but only in | |
// sync ops. They can not be used in async ops at all. | |
struct GcResourceSyncMutable; | |
impl GcResourceMutability for GcResourceSyncMutable {} | |
trait GcResource { | |
type Mutability: GcResourceMutability; | |
} | |
// -- AN IMMUTABLE STRUCT -- | |
struct DataResource {} | |
impl GcResource for DataResource { | |
type Mutability = GcResourceImmutable; | |
} | |
fn op_data_read(#[gc] data: &DataResource) {} // this is OK | |
fn op_data_write(#[gc] data: &mut DataResource) {} // this is NOT OK | |
async fn op_data_read_async(#[gc] data: &DataResource) {} // this is OK | |
async fn op_data_write_async(#[gc] data: &mut DataResource) {} // this is NOT OK | |
// -- A MUTABLE STRUCT -- | |
struct SocketResource {} | |
impl GcResource for SocketResource { | |
type Mutability = GcResourceSyncMutable; | |
} | |
fn op_data_read(#[gc] socket: &SocketResource) {} // this is OK | |
fn op_data_write(#[gc] socket: &mut SocketResource) {} // this is NOT OK | |
async fn op_data_read_async(#[gc] socket: &SocketResource) {} // this is NOT OK | |
async fn op_data_write_async(#[gc] socket: &mut SocketResource) {} // this is NOT OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment