Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #244 from GuillaumeGomez/display-and-debug
Browse files Browse the repository at this point in the history
Implement Display and Debug traits
  • Loading branch information
GuillaumeGomez committed Feb 18, 2019
2 parents e6567eb + d53ab0d commit 6c211fd
Show file tree
Hide file tree
Showing 17 changed files with 676 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cairo-sys-rs/src/lib.rs
Expand Up @@ -249,6 +249,12 @@ impl Default for Matrix {
}
}

impl ::std::fmt::Display for Matrix {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "Matrix")
}
}

#[repr(C)]
#[derive(Clone, Copy, Default, Debug)]
pub struct cairo_user_data_key_t {
Expand Down
26 changes: 24 additions & 2 deletions src/context.rs
Expand Up @@ -6,7 +6,9 @@
use glib::translate::*;
use libc::c_int;
use std::ffi::CString;
use std::fmt;
use std::ops;
use std::slice;
use ::paths::Path;
use ::font::{TextExtents, TextCluster, FontExtents, ScaledFont, FontOptions, FontFace, Glyph};
use ::matrices::{Matrix, MatrixTrait};
Expand Down Expand Up @@ -40,8 +42,6 @@ impl ops::Deref for RectangleList {
type Target = [Rectangle];

fn deref(&self) -> &[Rectangle] {
use std::slice;

unsafe {
let ptr = (*self.ptr).rectangles as *mut Rectangle;
let len = (*self.ptr).num_rectangles;
Expand All @@ -63,6 +63,22 @@ impl Drop for RectangleList {
}
}

impl fmt::Debug for RectangleList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
f.debug_tuple("RectangleList")
.field(&*self)
.finish()
}
}
}

impl fmt::Display for RectangleList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "RectangleList")
}
}

#[derive(Debug)]
pub struct Context(*mut cairo_t, bool);

Expand Down Expand Up @@ -911,6 +927,12 @@ impl Context {
}
}

impl fmt::Display for Context {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Context")
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 6c211fd

Please sign in to comment.