Skip to content

Commit 8aa15d1

Browse files
committed
log: Make it optional feature
1 parent 6f1cfc6 commit 8aa15d1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

qmetaobject/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ keywords = ["Qt", "QML", "QMetaObject",]
1111
repository = "https://github.com/woboq/qmetaobject-rs"
1212

1313
[features]
14+
default = ["log"]
1415
chrono_qdatetime = ["chrono"]
1516

1617
[dependencies]
1718
qmetaobject_impl = { path = "../qmetaobject_impl", version = "=0.1.4"}
1819
lazy_static = "1.0"
19-
log = "0.4"
2020
cpp = "0.5.4"
2121
chrono = { version = "0.4", optional = true }
22+
log = { version = "0.4", optional = true }
2223

2324
[build-dependencies]
2425
cpp_build = "0.5.4"
@@ -29,7 +30,6 @@ cstr = "0.1"
2930
if_rust_version = "1"
3031
tempfile = "^3"
3132

32-
3333
[package.metadata.docs.rs]
3434
dependencies = [ "qtbase5-dev", "qtdeclarative5-dev" ]
3535
rustc-args = [ "--cfg feature=\"docs-only\"" ]

qmetaobject/src/log.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::os::raw::c_char;
44

5+
#[cfg(feature = "log")]
56
use log::{Level, logger, Record};
67

78
use crate::QString;
@@ -74,6 +75,7 @@ pub enum QtMsgType {
7475
// QtSystemMsg = QtCriticalMsg
7576
}
7677

78+
#[cfg(feature = "log")]
7779
impl From<QtMsgType> for Level {
7880
/// Mapping from Qt logging levels to Rust logging facade's levels.
7981
///
@@ -97,6 +99,7 @@ impl From<QtMsgType> for Level {
9799
}
98100
}
99101

102+
#[cfg(feature = "log")]
100103
impl From<Level> for QtMsgType {
101104
/// Mapping back from Rust logging facade's levels to Qt logging levels.
102105
///
@@ -130,6 +133,7 @@ pub fn install_message_handler(logger: extern "C" fn(QtMsgType, &QMessageLogCont
130133
// It is called from Qt code, then it converts Qt logging data
131134
// into Rust logging facade's log::Record object, and sends it
132135
// to the currently active logger.
136+
#[cfg(feature = "log")]
133137
extern "C" fn log_capture(msg_type: QtMsgType,
134138
context: &QMessageLogContext,
135139
message: &QString) {
@@ -179,6 +183,7 @@ extern "C" fn log_capture(msg_type: QtMsgType,
179183
/// [log]: https://docs.rs/log
180184
/// [`log::Record`]: https://docs.rs/log/0.4.10/log/struct.Record.html
181185
/// [lvl]: ./struct.QtMsgType.html
186+
#[cfg(feature = "log")]
182187
pub fn init_qt_to_rust() {
183188
// The reason it is named so complex instead of simple `init` is that
184189
// such descriptive name is future-proof. Consider if someone someday
@@ -187,6 +192,7 @@ pub fn init_qt_to_rust() {
187192
}
188193

189194
#[cfg(test)]
195+
#[cfg(feature = "log")]
190196
mod tests {
191197
use super::*;
192198

0 commit comments

Comments
 (0)