Skip to content

Commit

Permalink
feat: hide serde behind a feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugal31 committed Jul 13, 2021
1 parent 10036ad commit fd7646d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -19,7 +19,7 @@ vendored = ["yara-sys/vendored"]
[dependencies]
thiserror = "1.0"
lazy_static = "1.3.0"
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
crossbeam = "0.7"
Expand Down
7 changes: 5 additions & 2 deletions src/matches.rs
@@ -1,6 +1,9 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A match within a scan.
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Match {
/// Offset of the match within the scanning area.
pub offset: usize,
Expand Down
13 changes: 9 additions & 4 deletions src/rules.rs
Expand Up @@ -2,8 +2,10 @@ use std::convert::TryFrom;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use yara_sys::scan_flags::*;
use serde::{Serialize, Deserialize};

use crate::{errors::*, initialize::InitializationToken, internals, YrString};

Expand Down Expand Up @@ -188,7 +190,8 @@ impl Drop for Rules {

/// A rule that matched during a scan.

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rule<'r> {
/// Name of the rule.
pub identifier: &'r str,
Expand All @@ -203,14 +206,16 @@ pub struct Rule<'r> {
}

/// Metadata specified in a rule.
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Metadata<'r> {
pub identifier: &'r str,
pub value: MetadataValue<'r>,
}

/// Type of the value in [MetaData](struct.Metadata.html)
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MetadataValue<'r> {
Integer(i64),
String(&'r str),
Expand Down
6 changes: 4 additions & 2 deletions src/string.rs
@@ -1,8 +1,10 @@
use crate::Match;
use serde::{Serialize, Deserialize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A matcher string that matched during a scan.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct YrString<'a> {
/// Name of the string, with the '$'.
pub identifier: &'a str,
Expand Down

0 comments on commit fd7646d

Please sign in to comment.