Skip to main content

qfall_math/integer/z/
unsafe_functions.rs

1// Copyright 2025 Jan Niklas Siemer
2//
3// This file is part of qFALL-math.
4//
5// qFALL-math is free software: you can redistribute it and/or modify it under
6// the terms of the Mozilla Public License Version 2.0 as published by the
7// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8
9//! This module contains public functions that enable access to underlying
10//! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe.
11
12use crate::{
13    integer::Z,
14    macros::unsafe_passthrough::{unsafe_getter, unsafe_setter},
15};
16use flint3_sys::{fmpz, fmpz_clear};
17
18unsafe_getter!(Z, value, fmpz);
19unsafe_setter!(Z, value, fmpz, fmpz_clear);
20
21#[cfg(test)]
22mod test_get_fmpz {
23    use super::Z;
24
25    /// Checks availability of the getter for [`Z::value`]
26    /// and its ability to be modified.
27    #[test]
28    #[allow(unused_mut)]
29    fn availability() {
30        let mut integer = Z::from(1);
31
32        let mut fmpz_int = unsafe { integer.get_fmpz() };
33
34        assert_eq!(&1, fmpz_int);
35    }
36}
37
38#[cfg(test)]
39mod test_set_fmpz {
40    use super::Z;
41    use flint3_sys::fmpz;
42
43    /// Checks availability of the setter for [`Z::value`]
44    /// and its ability to modify [`Z`].
45    #[test]
46    #[allow(unused_mut)]
47    fn availability_and_modification() {
48        let mut integer = Z::from(1);
49        let b: fmpz = 2;
50
51        unsafe { integer.set_fmpz(b) };
52
53        assert_eq!(Z::from(2), integer);
54    }
55}