Skip to content

Commit

Permalink
Implement the example prime library with rust
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgoss committed Sep 29, 2023
1 parent ab3ecdd commit b60f3ad
Show file tree
Hide file tree
Showing 10 changed files with 1,204 additions and 0 deletions.
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"]
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},
}
}
}
Loading

0 comments on commit b60f3ad

Please sign in to comment.