Content-Length: 351905 | pFad | http://github.com/RustPython/RustPython/pull/707/commits/0b1b6682c16eee99c44bfd9654aea42445311c80

F0 Fix the Display impl for PyRef by OddCoincidence · Pull Request #707 · RustPython/RustPython · GitHub
Skip to content

Fix the Display impl for PyRef #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Display impl for PyRef
  • Loading branch information
OddCoincidence committed Mar 21, 2019
commit 0b1b6682c16eee99c44bfd9654aea42445311c80
9 changes: 4 additions & 5 deletions vm/src/obj/objstr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::hash::{Hash, Hasher};
use std::ops::Range;
use std::str::FromStr;
Expand Down Expand Up @@ -25,11 +26,9 @@ pub struct PyString {
pub value: String,
}

impl<T: ToString> From<T> for PyString {
fn from(t: T) -> PyString {
PyString {
value: t.to_string(),
}
impl fmt::Display for PyString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.value, f)
}
}

Expand Down
7 changes: 7 additions & 0 deletions vm/src/obj/objtype.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;

use crate::function::PyFuncArgs;
use crate::pyobject::{
Expand All @@ -20,6 +21,12 @@ pub struct PyClass {
pub mro: Vec<PyClassRef>,
}

impl fmt::Display for PyClass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.name, f)
}
}

pub type PyClassRef = PyRef<PyClass>;

impl PyValue for PyClass {
Expand Down
8 changes: 6 additions & 2 deletions vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,13 @@ impl<T> IntoPyObject for PyRef<T> {
}
}

impl<T> fmt::Display for PyRef<T> {
impl<T: fmt::Display> fmt::Display for PyRef<T>
where
T: PyValue + fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.obj.fmt(f)
let value: &T = self.obj.payload().expect("unexpected payload for type");
fmt::Display::fmt(value, f)
}
}

Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/pull/707/commits/0b1b6682c16eee99c44bfd9654aea42445311c80

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy