github.com/searKing/golang/go@v1.2.117/io/adaptor.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package io
     6  
     7  type WriterFunc func(p []byte) (n int, err error)
     8  
     9  func (f WriterFunc) Write(p []byte) (n int, err error) {
    10  	return f(p)
    11  }
    12  
    13  type WriterFuncPrintfLike func(format string, args ...any)
    14  
    15  func (f WriterFuncPrintfLike) Write(p []byte) (n int, err error) {
    16  	f("%s", string(p))
    17  	return len(p), nil
    18  }