Writer
The point of this interface is to allow the instance to be efficiently
written into a Writer
.
Ready-to-save documents usually provide this interface.
core :: Writable :: defaultinit
core :: Writable :: write_to_bytes
Likewrite_to
but return a new Bytes (may be quite large)
core :: Writable :: write_to_file
Likewrite_to
but take care of creating the file
core :: Writable :: write_to_string
Likewrite_to
but return a new String (may be quite large).
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Writable :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).core :: Writable :: write_to_bytes
Likewrite_to
but return a new Bytes (may be quite large)
core :: Writable :: write_to_file
Likewrite_to
but take care of creating the file
core :: Writable :: write_to_string
Likewrite_to
but return a new String (may be quite large).
html :: NitHomepage
template :: TmplComposerDetail
A composer in the detailled list of composers
# Things that can be efficienlty written to a `Writer`
#
# The point of this interface is to allow the instance to be efficiently
# written into a `Writer`.
#
# Ready-to-save documents usually provide this interface.
interface Writable
# Write itself to a `stream`
# The specific logic it let to the concrete subclasses
fun write_to(stream: Writer) is abstract
# Like `write_to` but return a new String (may be quite large).
#
# This functionality is anecdotal, since the point
# of a streamable object is to be efficiently written to a
# stream without having to allocate and concatenate strings.
fun write_to_string: String
do
var stream = new StringWriter
write_to(stream)
return stream.to_s
end
# Like `write_to` but return a new Bytes (may be quite large)
#
# This functionality is anecdotal, since the point
# of a streamable object is to be efficiently written to a
# stream without having to allocate and concatenate buffers.
#
# Nevertheless, you might need this method if you want to know
# the byte size of a writable object.
fun write_to_bytes: Bytes
do
var stream = new BytesWriter
write_to(stream)
return stream.bytes
end
end
lib/core/stream.nit:547,1--584,3