-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the example prime library with rust
- Loading branch information
1 parent
ab3ecdd
commit b60f3ad
Showing
10 changed files
with
1,204 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Examples/Primes/LibPrimes_component/Implementations/Rust/Cargo.toml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (C) 2019 PrimeDevelopers | ||
# | ||
# All rights reserved. | ||
# | ||
# This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. | ||
# | ||
# Abstract: This is an autogenerated Cargo file for the development of Prime Numbers Library. | ||
# | ||
# Interface version: 1.2.0 | ||
|
||
[package] | ||
name = "primes" | ||
version = "0.1.0" | ||
[lib] | ||
path = "lib.rs" | ||
crate-type = ["cdylib"] |
93 changes: 93 additions & 0 deletions
93
.../Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_handle.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*++ | ||
Copyright (C) 2019 PrimeDevelopers | ||
All rights reserved. | ||
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. | ||
Abstract: This is an autogenerated Rust implementation file in order to allow easy | ||
development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. | ||
Interface version: 1.2.0 | ||
*/ | ||
|
||
|
||
// Handle passed through interface define the casting maps needed to extract | ||
|
||
use libprimes_interfaces::*; | ||
|
||
#[allow(dead_code)] | ||
impl HandleImpl { | ||
pub fn as_base(&self) -> Option<&dyn Base> { | ||
match self { | ||
HandleImpl::TCalculator(_, ptr) => Some(ptr.as_ref()), | ||
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()), | ||
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()), | ||
_ => None | ||
} | ||
} | ||
pub fn as_mut_base(&mut self) -> Option<&mut dyn Base> { | ||
match self { | ||
HandleImpl::TCalculator(_, ptr) => Some(ptr.as_mut()), | ||
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()), | ||
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()), | ||
_ => None | ||
} | ||
} | ||
|
||
pub fn as_calculator(&self) -> Option<&dyn Calculator> { | ||
match self { | ||
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()), | ||
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()), | ||
_ => None | ||
} | ||
} | ||
pub fn as_mut_calculator(&mut self) -> Option<&mut dyn Calculator> { | ||
match self { | ||
HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()), | ||
HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()), | ||
_ => None | ||
} | ||
} | ||
|
||
pub fn as_factorization_calculator(&self) -> Option<&dyn FactorizationCalculator> { | ||
match self { | ||
_ => None | ||
} | ||
} | ||
pub fn as_mut_factorization_calculator(&mut self) -> Option<&mut dyn FactorizationCalculator> { | ||
match self { | ||
_ => None | ||
} | ||
} | ||
|
||
pub fn as_sieve_calculator(&self) -> Option<&dyn SieveCalculator> { | ||
match self { | ||
_ => None | ||
} | ||
} | ||
pub fn as_mut_sieve_calculator(&mut self) -> Option<&mut dyn SieveCalculator> { | ||
match self { | ||
_ => None | ||
} | ||
} | ||
|
||
pub fn inc_ref_count(&mut self) { | ||
match self { | ||
HandleImpl::TBase(count, _) => *count += 1, | ||
HandleImpl::TCalculator(count, _) => *count += 1, | ||
HandleImpl::TFactorizationCalculator(count, _) => *count += 1, | ||
HandleImpl::TSieveCalculator(count, _) => *count += 1, | ||
} | ||
} | ||
pub fn dec_ref_count(&mut self) -> bool { | ||
match self { | ||
HandleImpl::TBase(count, _) => {*count -= 1; *count == 0}, | ||
HandleImpl::TCalculator(count, _) => {*count -= 1; *count == 0}, | ||
HandleImpl::TFactorizationCalculator(count, _) => {*count -= 1; *count == 0}, | ||
HandleImpl::TSieveCalculator(count, _) => {*count -= 1; *count == 0}, | ||
} | ||
} | ||
} |
Oops, something went wrong.