Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsafe marker from SystemData functions #34

Merged
merged 1 commit into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/custom_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ impl<'a> SystemData<'a> for ExampleBundle<'a> {
}
}

unsafe fn reads(id: usize) -> Vec<ResourceId> {
fn reads(id: usize) -> Vec<ResourceId> {
vec![ResourceId::new_with_id::<ResA>(id)]
}

unsafe fn writes(id: usize) -> Vec<ResourceId> {
fn writes(id: usize) -> Vec<ResourceId> {
vec![ResourceId::new_with_id::<ResB>(id)]
}
}
Expand Down
4 changes: 2 additions & 2 deletions shred-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn impl_system_data(ast: &MacroInput) -> Tokens {
#fetch_return
}

unsafe fn reads(id: usize) -> Vec<::shred::ResourceId> {
fn reads(id: usize) -> Vec<::shred::ResourceId> {
let mut r = Vec::new();

#( {
Expand All @@ -61,7 +61,7 @@ fn impl_system_data(ast: &MacroInput) -> Tokens {
r
}

unsafe fn writes(id: usize) -> Vec<::shred::ResourceId> {
fn writes(id: usize) -> Vec<::shred::ResourceId> {
let mut r = Vec::new();

#( {
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ impl<'t> DispatcherBuilder<'t> {
where T: for<'a> System<'a> + Send + 't
{
let id = self.systems.len();
let reads = unsafe { T::SystemData::reads(data_id) };
let writes = unsafe { T::SystemData::writes(data_id) };
let reads = T::SystemData::reads(data_id);
let writes = T::SystemData::writes(data_id);

let dependencies: Vec<usize> = dep.iter()
.map(|x| {
Expand Down
16 changes: 8 additions & 8 deletions src/res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl<'a, T> SystemData<'a> for Fetch<'a, T>
res.fetch(id)
}

unsafe fn reads(id: usize) -> Vec<ResourceId> {
fn reads(id: usize) -> Vec<ResourceId> {
vec![ResourceId::new_with_id::<T>(id)]
}

unsafe fn writes(_: usize) -> Vec<ResourceId> {
fn writes(_: usize) -> Vec<ResourceId> {
vec![]
}
}
Expand Down Expand Up @@ -113,11 +113,11 @@ impl<'a, T> SystemData<'a> for FetchMut<'a, T>
res.fetch_mut(id)
}

unsafe fn reads(_: usize) -> Vec<ResourceId> {
fn reads(_: usize) -> Vec<ResourceId> {
vec![]
}

unsafe fn writes(id: usize) -> Vec<ResourceId> {
fn writes(id: usize) -> Vec<ResourceId> {
vec![ResourceId::new_with_id::<T>(id)]
}
}
Expand Down Expand Up @@ -311,9 +311,9 @@ mod tests {

#[test]
fn fetch_aspects() {
assert_eq!(unsafe { Fetch::<Res>::reads(4) },
assert_eq!(Fetch::<Res>::reads(4),
vec![ResourceId::new_with_id::<Res>(4)]);
assert_eq!(unsafe { Fetch::<Res>::writes(8) }, vec![]);
assert_eq!(Fetch::<Res>::writes(8), vec![]);

let mut res = Resources::new();
res.add_with_id(Res, 56);
Expand All @@ -322,8 +322,8 @@ mod tests {

#[test]
fn fetch_mut_aspects() {
assert_eq!(unsafe { FetchMut::<Res>::reads(4) }, vec![]);
assert_eq!(unsafe { FetchMut::<Res>::writes(8) },
assert_eq!(FetchMut::<Res>::reads(4), vec![]);
assert_eq!(FetchMut::<Res>::writes(8),
vec![ResourceId::new_with_id::<Res>(8)]);

let mut res = Resources::new();
Expand Down
12 changes: 6 additions & 6 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait SystemData<'a> {
/// This method is only executed once,
/// thus the returned value may never change
/// (otherwise it has no effect).
unsafe fn reads(id: usize) -> Vec<ResourceId>;
fn reads(id: usize) -> Vec<ResourceId>;

/// A list of [`ResourceId`]s the bundle
/// needs write access to in order to
Expand All @@ -62,7 +62,7 @@ pub trait SystemData<'a> {
/// This method is only executed once,
/// thus the returned value may never change
/// (otherwise it has no effect).
unsafe fn writes(id: usize) -> Vec<ResourceId>;
fn writes(id: usize) -> Vec<ResourceId>;
}

macro_rules! impl_data {
Expand All @@ -76,7 +76,7 @@ macro_rules! impl_data {
( $( <$ty as SystemData<'a>>::fetch(res, id.clone()), )* )
}

unsafe fn reads(id: usize) -> Vec<ResourceId> {
fn reads(id: usize) -> Vec<ResourceId> {
#![allow(unused_mut)]

let mut r = Vec::new();
Expand All @@ -89,7 +89,7 @@ macro_rules! impl_data {
r
}

unsafe fn writes(id: usize) -> Vec<ResourceId> {
fn writes(id: usize) -> Vec<ResourceId> {
#![allow(unused_mut)]

let mut r = Vec::new();
Expand All @@ -110,11 +110,11 @@ impl<'a> SystemData<'a> for () {
()
}

unsafe fn reads(_: usize) -> Vec<ResourceId> {
fn reads(_: usize) -> Vec<ResourceId> {
Vec::new()
}

unsafe fn writes(_: usize) -> Vec<ResourceId> {
fn writes(_: usize) -> Vec<ResourceId> {
Vec::new()
}
}
Expand Down