-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust: move CDict wrapper to own module
I want to consolidate all the safe wrappers in their own module to make it easier to port them upstream.
- Loading branch information
Showing
3 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
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
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
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,35 @@ | ||
// Copyright (c) 2020-present, Gregory Szorc | ||
// All rights reserved. | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the BSD license. See the LICENSE file for details. | ||
|
||
use std::marker::PhantomData; | ||
|
||
/// Safe wrapper for ZSTD_CDict instances. | ||
pub(crate) struct CDict<'a> { | ||
// TODO don't expose field. | ||
pub(crate) ptr: *mut zstd_sys::ZSTD_CDict, | ||
_phantom: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> CDict<'a> { | ||
pub fn from_ptr(ptr: *mut zstd_sys::ZSTD_CDict) -> Self { | ||
Self { | ||
ptr, | ||
_phantom: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Drop for CDict<'a> { | ||
fn drop(&mut self) { | ||
unsafe { | ||
zstd_sys::ZSTD_freeCDict(self.ptr); | ||
} | ||
} | ||
} | ||
|
||
unsafe impl<'a> Send for CDict<'a> {} | ||
|
||
unsafe impl<'a> Sync for CDict<'a> {} |