@@ -73,63 +73,49 @@ pub enum QtMsgType {
73
73
// QtSystemMsg = QtCriticalMsg
74
74
}
75
75
76
- /// Mapping from Qt logging levels to Rust logging facade's levels.
77
- ///
78
- /// Due to the limited range of levels from both sides,
79
- /// [`QtCriticalMsg`][`QtMsgType`] and [`QtFatalMsg`][`QtMsgType`]
80
- /// both map to [`log::Level::Error`][Level],
81
- /// while [`log::Level::Trace`][Level] is never returned.
82
- ///
83
- /// [Level]: https://docs.rs/log/0.4.10/log/enum.Level.html
84
- /// [`QtMsgType`]: https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum
85
- pub fn map_level ( lvl : QtMsgType ) -> Level {
86
- match lvl {
87
- QtDebugMsg => Level :: Debug ,
88
- QtInfoMsg => Level :: Info ,
89
- QtWarningMsg => Level :: Warn ,
90
- QtCriticalMsg => Level :: Error ,
91
- QtFatalMsg => Level :: Error ,
92
- // XXX: What are the external guarantees about possible values of QtMsgType?
93
- // XXX: Are they promised to be limited to the valid enum variants?
94
- }
95
- }
96
-
97
- /// Mapping back from Rust logging facade's levels to Qt logging levels.
98
- ///
99
- /// Not used internally, exists just for completeness of API.
100
- ///
101
- /// Due to the limited range of levels from both sides,
102
- /// [`log::Level::Debug`][Level] and [`log::Level::Trace`][Level]
103
- /// both map to [`QtDebugMsg`][`QtMsgType`],
104
- /// while [`QtFatalMsg`][`QtMsgType`] is never returned.
105
- ///
106
- /// [Level]: https://docs.rs/log/0.4.10/log/enum.Level.html
107
- /// [`QtMsgType`]: https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum
108
- pub fn unmap_level ( lvl : Level ) -> QtMsgType {
109
- match lvl {
110
- Level :: Error => QtCriticalMsg ,
111
- Level :: Warn => QtWarningMsg ,
112
- Level :: Info => QtInfoMsg ,
113
- Level :: Debug => QtDebugMsg ,
114
- Level :: Trace => QtDebugMsg ,
115
- }
116
- }
117
-
118
76
impl From < QtMsgType > for Level {
119
- /// Delegates to [default][] mapping algorithm.
77
+ /// Mapping from Qt logging levels to Rust logging facade's levels.
78
+ ///
79
+ /// Due to the limited range of levels from both sides,
80
+ /// [`QtCriticalMsg`][`Qt::QtMsgType`] and [`QtFatalMsg`][`Qt::QtMsgType`]
81
+ /// both map to [`log::Level::Error`][Level],
82
+ /// while [`log::Level::Trace`][Level] is never returned.
120
83
///
121
- /// [default]: ./fn.map_level.html
84
+ /// [Level]: https://docs.rs/log/0.4.10/log/enum.Level.html
85
+ /// [`Qt::QtMsgType`]: https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum
122
86
fn from ( lvl : QtMsgType ) -> Self {
123
- map_level ( lvl)
87
+ match lvl {
88
+ QtDebugMsg => Level :: Debug ,
89
+ QtInfoMsg => Level :: Info ,
90
+ QtWarningMsg => Level :: Warn ,
91
+ QtCriticalMsg => Level :: Error ,
92
+ QtFatalMsg => Level :: Error ,
93
+ // XXX: What are the external guarantees about possible values of QtMsgType?
94
+ // XXX: Are they promised to be limited to the valid enum variants?
95
+ }
124
96
}
125
97
}
126
98
127
99
impl From < Level > for QtMsgType {
128
- /// Delegates to [default][] mapping algorithm.
100
+ /// Mapping back from Rust logging facade's levels to Qt logging levels.
101
+ ///
102
+ /// Not used internally, exists just for completeness of API.
129
103
///
130
- /// [default]: ./fn.unmap_level.html
104
+ /// Due to the limited range of levels from both sides,
105
+ /// [`log::Level::Debug`][Level] and [`log::Level::Trace`][Level]
106
+ /// both map to [`QtDebugMsg`][`Qt::QtMsgType`],
107
+ /// while [`QtFatalMsg`][`Qt::QtMsgType`] is never returned.
108
+ ///
109
+ /// [Level]: https://docs.rs/log/0.4.10/log/enum.Level.html
110
+ /// [`Qt::QtMsgType`]: https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum
131
111
fn from ( lvl : Level ) -> Self {
132
- unmap_level ( lvl)
112
+ match lvl {
113
+ Level :: Error => QtCriticalMsg ,
114
+ Level :: Warn => QtWarningMsg ,
115
+ Level :: Info => QtInfoMsg ,
116
+ Level :: Debug => QtDebugMsg ,
117
+ Level :: Trace => QtDebugMsg ,
118
+ }
133
119
}
134
120
}
135
121
@@ -184,14 +170,14 @@ extern "C" fn log_capture(msg_type: QtMsgType,
184
170
/// [Rust logging facade][log].
185
171
///
186
172
/// Most metadata from Qt logging context is retained and passed to [`log::Record`][].
187
- /// Logging levels are mapped with the [ default][map_level] algorithm .
173
+ /// Logging levels are mapped with the default [`From`][lvl] implementation .
188
174
///
189
175
/// This function may be called more than once.
190
176
///
191
177
/// [qt-log]: https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler
192
178
/// [log]: https://docs.rs/log
193
179
/// [`log::Record`]: https://docs.rs/log/0.4.10/log/struct.Record.html
194
- /// [map_level ]: ./fn.map_level .html
180
+ /// [lvl ]: ./struct.QtMsgType .html
195
181
pub fn init_qt_to_rust ( ) {
196
182
// The reason it is named so complex instead of simple `init` is that
197
183
// such descriptive name is future-proof. Consider if someone someday
0 commit comments