| vector.rs (e60d507d35e0fc62a9fa0cec36b2c643702b7059) | vector.rs (78c2cefab85ecc740ba63f6df2f5d30a7426d159) |
|---|---|
| 1// Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8//! A Ceed Vector constitutes the main data structure and serves as input/output --- 20 unchanged lines hidden (view full) --- 29 fn from(vec: &'a Vector) -> Self { 30 debug_assert!(vec.ptr != unsafe { bind_ceed::CEED_VECTOR_ACTIVE }); 31 debug_assert!(vec.ptr != unsafe { bind_ceed::CEED_VECTOR_NONE }); 32 Self::Some(vec) 33 } 34} 35impl<'a> VectorOpt<'a> { 36 /// Transform a Rust libCEED VectorOpt into C libCEED CeedVector | 1// Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8//! A Ceed Vector constitutes the main data structure and serves as input/output --- 20 unchanged lines hidden (view full) --- 29 fn from(vec: &'a Vector) -> Self { 30 debug_assert!(vec.ptr != unsafe { bind_ceed::CEED_VECTOR_ACTIVE }); 31 debug_assert!(vec.ptr != unsafe { bind_ceed::CEED_VECTOR_NONE }); 32 Self::Some(vec) 33 } 34} 35impl<'a> VectorOpt<'a> { 36 /// Transform a Rust libCEED VectorOpt into C libCEED CeedVector |
| 37 pub(crate) fn to_raw(self) -> bind_ceed::CeedVector { | 37 pub(crate) fn to_raw(&self) -> bind_ceed::CeedVector { |
| 38 match self { 39 Self::Some(vec) => vec.ptr, 40 Self::Active => unsafe { bind_ceed::CEED_VECTOR_ACTIVE }, 41 Self::None => unsafe { bind_ceed::CEED_VECTOR_NONE }, 42 } 43 } 44 45 /// Check if a VectorOpt is Some --- 334 unchanged lines hidden (view full) --- 380 /// assert_eq!(vec.len(), 10, "Incorrect length"); 381 /// # Ok(()) 382 /// # } 383 /// ``` 384 pub fn len(&self) -> usize { 385 self.length() 386 } 387 | 38 match self { 39 Self::Some(vec) => vec.ptr, 40 Self::Active => unsafe { bind_ceed::CEED_VECTOR_ACTIVE }, 41 Self::None => unsafe { bind_ceed::CEED_VECTOR_NONE }, 42 } 43 } 44 45 /// Check if a VectorOpt is Some --- 334 unchanged lines hidden (view full) --- 380 /// assert_eq!(vec.len(), 10, "Incorrect length"); 381 /// # Ok(()) 382 /// # } 383 /// ``` 384 pub fn len(&self) -> usize { 385 self.length() 386 } 387 |
| 388 /// Returns true if the Vector contains no elements 389 /// 390 /// ``` 391 /// # use libceed::prelude::*; 392 /// # fn main() -> libceed::Result<()> { 393 /// # let ceed = libceed::Ceed::default_init(); 394 /// let vec = ceed.vector(10)?; 395 /// assert!(!vec.is_empty(), "Incorrect emptiness"); 396 /// let empty_vec = ceed.vector(0)?; 397 /// assert!(empty_vec.is_empty(), "Incorrect emptiness"); 398 /// # Ok(()) 399 /// # } 400 /// ``` 401 pub fn is_empty(&self) -> bool { 402 self.length() == 0 403 } 404 |
|
| 388 /// Set the Vector to a constant value 389 /// 390 /// # arguments 391 /// 392 /// * `val` - Value to be used 393 /// 394 /// ``` 395 /// # use libceed::prelude::*; --- 479 unchanged lines hidden --- | 405 /// Set the Vector to a constant value 406 /// 407 /// # arguments 408 /// 409 /// * `val` - Value to be used 410 /// 411 /// ``` 412 /// # use libceed::prelude::*; --- 479 unchanged lines hidden --- |