qfall_math/integer/z/
unsafe_functions.rs

1// Copyright © 2025 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 flint_sys::fmpz::{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_and_modification() {
30        let mut integer = Z::from(1);
31
32        let mut fmpz_int = unsafe { integer.get_fmpz() };
33
34        fmpz_int.0 = 2;
35
36        assert_eq!(Z::from(2), integer);
37    }
38}
39
40#[cfg(test)]
41mod test_set_fmpz {
42    use super::Z;
43    use flint_sys::fmpz::fmpz;
44
45    /// Checks availability of the setter for [`Z::value`]
46    /// and its ability to modify [`Z`].
47    #[test]
48    #[allow(unused_mut)]
49    fn availability_and_modification() {
50        let mut integer = Z::from(1);
51        let b = fmpz(2);
52
53        unsafe { integer.set_fmpz(b) };
54
55        assert_eq!(Z::from(2), integer);
56    }
57}